TransWikia.com

Excel2latex produces broken vertical lines

TeX - LaTeX Asked by Vim on November 1, 2021

So I used Excel2latex to convert the following table into latex code:

enter image description here

The code produced (along with the environment to make a MWE) is:

documentclass[11pt,a4paper]{article}
usepackage[a4paper,hmargin={2.54cm,2.54cm},vmargin={3.17cm,3.17cm}]{geometry}
usepackage{amsmath}
usepackage{amssymb}
usepackage{amsfonts}
usepackage{mathrsfs}
usepackage{amsthm}
usepackage{tikz}
usepackage{bm}
usepackage{booktabs}

begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet2'
begin{table}[htbp]
  centering
  caption{Add caption}
    begin{tabular}{|r|r|r|}
    toprule
    Date  & open  & high \
    midrule
    2016-07-11 & 650.3800 & 651.9800 \
    midrule
    2016-07-12 & 651.2500 & 675.5000 \
    midrule
    2016-07-13 & 666.2500 & 671.4500 \
    midrule
    2016-07-14 & 655.3000 & 663.9900 \
    midrule
    2016-07-15 & 661.4000 & 669.9800 \
    midrule
    2016-07-18 & 680.0000 & 684.9400 \
    midrule
    2016-07-19 & 675.5100 & 676.8700 \
    bottomrule
    end{tabular}%
  label{tab:addlabel}%
end{table}%

end{document}

The output is:

enter image description here

with the vertical lines discontinued at every intersection with horizontal lines.

What I want is a table with unbroken, continuous vertical lines. What should I do? Thanks!

3 Answers

I will answer your question exactly, because it might be useful for other users of the very good excel2latex add-in to export an excel table to LaTeX with minimal effort. https://ctan.org/pkg/excel2latex?lang=en

So I used Excel2latex to convert the following table into latex code, ...

What I want is a table with continuous and unbroken vertical lines. That I have to do?

The culprit part in this case is booktabs, which insert a space between the rows to separate the contents of the cells from the horizontal lines. I ran into the same problem with vertical lines and also with colored rows or cells.

When using the excel2latex plugin, uncheck the option Booktabs package. The generated code will now insert bigstrut to achieve separation, so you will have to include usepackage{bigstrut} in your preamble.

It will use hline to draw the horizontal lines.

enter image description here

I started from your original code and just copied and pasted the result from excel2latex. The output exactly matches your requirements, including vertical and horizontal lines. I just added a caption for clarity.

What else can we require from a tool?

documentclass[11pt,a4paper]{article}
usepackage[a4paper,hmargin={2.54cm,2.54cm},vmargin={3.17cm,3.17cm}]{geometry}
usepackage{amsmath}
usepackage{amssymb}
usepackage{amsfonts}
usepackage{mathrsfs}
usepackage{amsthm}
usepackage{tikz}
usepackage{bm}
usepackage{booktabs}

usepackage{bigstrut} % added to replace booktabs

begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet2'
begin{table}[htbp]
  centering
  caption{With the booktabs option}
    begin{tabular}{|r|r|r|}
    toprule
    Date  & open  & high \
    midrule
    2016-07-11 & 650.3800 & 651.9800 \
    midrule
    2016-07-12 & 651.2500 & 675.5000 \
    midrule
    2016-07-13 & 666.2500 & 671.4500 \
    midrule
    2016-07-14 & 655.3000 & 663.9900 \
    midrule
    2016-07-15 & 661.4000 & 669.9800 \
    midrule
    2016-07-18 & 680.0000 & 684.9400 \
    midrule
    2016-07-19 & 675.5100 & 676.8700 \
    bottomrule
    end{tabular}%
  label{tab:addlabel}%
end{table}%


% Table generated by Excel2LaTeX from sheet 'Sheet1'
begin{table}[htbp]
    centering
    caption{Without the booktabs option}
    begin{tabular}{|r|r|r|}
        hline
        Date  &  open &  high bigstrut\
        hline
        2016-07-11 & 650.3800 & 651.9800 bigstrut\
        hline
        2016-07-12 & 651.2500 & 675.5000 bigstrut\
        hline
        2016-07-13 & 666.2500 & 671.4500 bigstrut\
        hline
        2016-07-14 & 655.3000 & 663.9900 bigstrut\
        hline
        2016-07-15 & 661.4000 & 669.9800 bigstrut\
        hline
        2016-07-18 & 680.0000 & 684.9400 bigstrut\
        hline
        2016-07-19 & 675.5100 & 676.8700 bigstrut\
        hline
    end{tabular}%
    label{tab:addlabel}%
end{table}%


end{document}

enter image description here

Answered by Simon Dispa on November 1, 2021

If you really want to add vertical rules (even if it is not in the spirit of booktabs) you can use {NiceTabular} of nicematrix which has a key vlines which will add all the vertical rules.

documentclass{article}
usepackage{booktabs}
usepackage{nicematrix}

begin{document}
begin{table}[htbp]
  centering
  caption{Add caption}
    begin{NiceTabular}{rrr}[vlines]
    toprule
    Date  & open  & high \
    midrule
    2016-07-11 & 650.3800 & 651.9800 \
    2016-07-12 & 651.2500 & 675.5000 \
    2016-07-13 & 666.2500 & 671.4500 \
    2016-07-14 & 655.3000 & 663.9900 \
    2016-07-15 & 661.4000 & 669.9800 \
    2016-07-18 & 680.0000 & 684.9400 \
    2016-07-19 & 675.5100 & 676.8700 \
    bottomrule
    end{NiceTabular}%
  label{tab:addlabel}%
end{table}%

end{document}

Prior to version 5.0 of nicematrix, you had to put {RRR} instead of {rrr}.

Output of the above code

Answered by F. Pantigny on November 1, 2021

booktabs discourages many horizontal lines, and strongly discourages vertical lines, to such an extant that it doesn't guarantee that vertical lines will work properly. The approach recommended by booktabs would be

documentclass{article}
usepackage{booktabs}

begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet2'
begin{table}[htbp]
  centering
  caption{Add caption}
    begin{tabular}{rrr}
    toprule
    Date  & open  & high \
    midrule
    2016-07-11 & 650.3800 & 651.9800 \
    2016-07-12 & 651.2500 & 675.5000 \
    2016-07-13 & 666.2500 & 671.4500 \
    2016-07-14 & 655.3000 & 663.9900 \
    2016-07-15 & 661.4000 & 669.9800 \
    2016-07-18 & 680.0000 & 684.9400 \
    2016-07-19 & 675.5100 & 676.8700 \
    bottomrule
    end{tabular}%
  label{tab:addlabel}%
end{table}%

end{document}

table output

Answered by Teepeemm on November 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP