8

I'm trying to create a table with horizontal and vertical lines, but the lines aren't meeting in the corners and I can't work out why. Can anyone point out what I'm doing wrong?

\documentclass[a4paper,10pt]{report}
\usepackage{booktabs}
\begin{document}

\begin{tabular} { | r | p{2cm} | p{2cm} | }
\toprule
\# & One & Two \\
\midrule
1 & alpha & bravo \\
2 & apple & banana \\
\bottomrule
\end{tabular}

\end{document}

Running this through a few different versions of pdflatex always produces this output, in Acrobat Reader and evince:

Example image showing lines not meeting in the corners

How do I get the horizontal and vertical lines to meet?

3
  • 8
    'Using vertical lines'. The booktabs manual explains that these should not be used, and also that they will not work with its rules. If you do want to create a grid, use the LaTeX horizontal line system.
    – Joseph Wright
    Jul 13, 2012 at 11:09
  • 1
    As you surely noticed, \toprule and \bottomrule draw a heavier rule than \midrule. This is a really good feature of booktabs (also the spacing is especially cared for), but it's of course incompatible with vertical rules. Simply don't use vertical rules and your table will be prettier.
    – egreg
    Jul 13, 2012 at 11:18
  • Ahh, of course! I just copied the code from a nice table that didn't have vertical lines, and didn't notice. Also, with respect, omitting vertical lines is a luxury reserved for those who haven't been forced to create a report with too many columns for the page width...
    – Malvineous
    Jul 13, 2012 at 11:26

2 Answers 2

7

enter image description here

\documentclass[border=10pt]{standalone}

\begin{document}

\begin{tabular} { | r | p{2cm} | p{2cm} | }
\hline
\# & One & Two \\
\hline
1 & alpha & bravo \\
2 & apple & banana \\
\hline
\end{tabular}

\end{document}

Edit 3

If you are a perfectionist, please consider the following defects at the intersection of horizontal and vertical lines.

enter image description here

Maybe you hate them even though they are small enough to be visible at a glance.

Edit 3.1

Based on Ulrike's comment below, we need to use array package to remove such a bad feature.

\documentclass[border=10pt]{standalone}

\usepackage{array}
\begin{document}

\begin{tabular} {|r|p{2cm}|p{2cm}|}
\hline
\# & One & Two \\
\hline
1 & alpha & bravo \\
2 & apple & banana \\
\hline
\end{tabular}

\end{document}

enter image description here

1
  • 1
    To get better corners: \usepackage{array}. Jul 13, 2012 at 11:59
0

A very similar answer, but please avoid using horizontal lines when you get a new advisor. =)

\documentclass[10pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}
\centering
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\begin{tabular} { | r | p{2cm} | p{2cm} | }
\toprule
\# & One & Two \\
\midrule
1 & alpha & bravo \\
2 & apple & banana \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

The corners are a tad better, and you can switch the \top-\mid and \bottomrule, to \hrule if you want. This is not a global change, but changes one table. For a more global solution simply put

\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}

in the preamble instead of inside the table.

1
  • 1
    while i agree that tables are generally (much!) better without horizontal lines, how do you deal with the problem of "too many columns" when you've already (1) decreased the size of the font, (2) set the table landscape, and (3) the table isn't amenable to having chunks taken out and presented separately? (in this situation, old or new advisor doesn't factor in.) Jul 13, 2012 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .