16

My vertical lines are being broken up (disrupted) by horizontal booktabs lines. How can I fix this?

It's well and good to say use \hline but I also need a cmidrule that spans only the second two columns which have no \hline equivalent to my knowledge. Also \hline is ugly because it doesn't automatically leave any vertical space between the line and the preceding/following lines of text.

Table

\documentclass[a4paper,12pt]{article}
\date{}
\usepackage{a4wide}
\usepackage{booktabs} %for top, middle and bottomline
\usepackage{multirow} %multi column and row spanning
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{blindtext}


    \begin{document}

    \begin{multicols}{2}

    \subsection*{Results}

 \resizebox{\columnwidth}{!}{%
\begin{tabular}{@{} l | c | c @{}}
\toprule
Characteristic & \multicolumn{2}{c}{Result}\\
 \cmidrule{2-3}
 & Seaweed isolate & Coral isolate \\
\midrule
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
\bottomrule
\end{tabular}
}

    \blindtext

    {\noindent
    \begin{tabularx}{\columnwidth}
    { | l | >{\raggedright\arraybackslash} X | >{\centering\arraybackslash} X | }
    Leave this column alone. & Left justify and adjust this column. &
    Centre and adjust this column. \\ 
    \end{tabularx}
    }

    \end{multicols}

    \end{document}
David Carlisle
  • 757,742
ptrcao
  • 6,603
  • You do know about \cline, I guess? It can be used to form 'grid lines' using a tabular, but as you say is horrible. – Joseph Wright May 12 '11 at 19:01
  • 3
    BTW, please consider editing your answer down to a minimal example: most of the packages you load are not needed. – Joseph Wright May 12 '11 at 19:02
  • 11
    (As you know about booktabs, I'm left wondering why you want vertical lines. The booktabs manual is pretty clear on why they are not a good thing in formal tables.) – Joseph Wright May 12 '11 at 19:05
  • Is there no way to do this with booktab rules? It does look awful with \cline and \hlines... (No automatic padding between text and rules; it has a very cramped appearance.) – ptrcao May 12 '11 at 19:10
  • 3
    @ptrcao: Please read the booktabs manual on this. As you should not have vertical rules in formal tables, they are not supported by booktabs. (I suspect the implementation would also be awkward, to say the least.) – Joseph Wright May 12 '11 at 19:14
  • To reinforce @Joseph Wright, Simon Fear does say, pretty clearly, that vertical lines in tables are a typographic abomination. My guess would be that if you want vertical lines, then booktabs isn't for you. – Brent.Longborough May 12 '11 at 19:17
  • 3
    Thanks, yeah, I know it is discouraged; rest assured, I've read the manual and I know the comment by the package author you refer to. The reason I'm using vertical rules is more because it is a publication convention. – ptrcao May 12 '11 at 19:23
  • 6
    I appreciate the advice and I know where it is coming from. I try to avoid it where I can. If anyone knows how to implement unbroken vertical lies with booktabs or otherwise to equivalent effect, I'd still be interested. – ptrcao May 12 '11 at 19:31

3 Answers3

26

You can use the \extrarowheight command from the array package to stretch all the rows. Otherwise you can define your own "strut" command to enlarge a single row. The code below is based on array's strut box. If you are using vertical lines, then us it on the sides also.

EDIT: There is also the bigstrut package

I have also include an example how to do it properly with booktabs

\documentclass{article}
\usepackage{array}
    %\setlength{\extrarowheight}{1pt}
\usepackage{booktabs} %for top, middle and bottomline
\usepackage{bigstrut}
    \setlength\bigstrutjot{3pt}

\makeatletter
\newlength\mylena
\newlength\mylenb
\newcommand\mystrut[1][2]{%
    \setlength\mylena{#1\ht\@arstrutbox}%
    \setlength\mylenb{#1\dp\@arstrutbox}%
    \rule[\mylenb]{0pt}{\mylena}}
\makeatother

\begin{document}
\noindent With mystrut\par
\bigskip
\begin{tabular}{|l|c|c|}
\hline
    \mystrut   & \multicolumn{2}{c|}{Result}\\
\cline{2-3}
    \mystrut
    Characteristic    & Seaweed isolate & Coral isolate  \\
\hline
    \mystrut
    Cell shape        & Rod             & Rod\\
    Gram stain        & $-$             & $-$\\
    Oxidase           & $+$             & $-$\\
    Catalase          & $+$             & $-$\\
    MSA               & Growth          & No growth\\
    Anaerobic         & Growth (weak)   & No growth\\
    Motility          &                 & \\
    Indole production &                 & \\
    Hugh \& Leifsons  &                 & \\
\hline
\end{tabular}

\bigskip
\noindent With bigstrut\par
\bigskip
\begin{tabular}{|l|c|c|}
\hline
    \bigstrut   & \multicolumn{2}{c|}{Result}\\
\cline{2-3}
    \bigstrut
    Characteristic    & Seaweed isolate & Coral isolate  \\
\hline
    \bigstrut[t]
    Cell shape        & Rod             & Rod\\
    Gram stain        & $-$             & $-$\\
    Oxidase           & $+$             & $-$\\
    Catalase          & $+$             & $-$\\
    MSA               & Growth          & No growth\\
    Anaerobic         & Growth (weak)   & No growth\\
    Motility          &                 & \\
    Indole production &                 & \\
    \bigstrut[b]
    Hugh \& Leifsons  &                 & \\
\hline
\end{tabular}

\bigskip
\noindent With booktabs\par
\bigskip
\begin{tabular}{@{}lcc@{}}
\toprule
                      & \multicolumn{2}{c@{}}{Result}\\
\cmidrule(l){2-3}
     Characteristic   & Seaweed isolate & Coral isolate \\
\cmidrule( r){1-1}
\cmidrule(lr){2-2}
\cmidrule(l ){3-3}
    Cell shape        & Rod             & Rod\\
    Gram stain        & $-$             & $-$\\
    Oxidase           & $+$             & $-$\\
    Catalase          & $+$             & $-$\\
    MSA               & Growth          & No growth\\
    Anaerobic         & Growth (weak)   & No growth\\
    Motility          &                 & \\
    Indole production &                 & \\
    Hugh \& Leifsons  &                 & \\
\bottomrule
\end{tabular}
\end{document}

The output is

enter image description here

David Carlisle
  • 757,742
Danie Els
  • 19,694
3

If you actually want to use vertical rules with the rules of booktabs (which is not at all in the spirit of booktabs), you can use {NiceTabular} of nicematrix.

\documentclass[a4paper,12pt]{article}
\usepackage{booktabs} 
\usepackage{amsmath}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{@{} l | c | c @{}} \toprule Characteristic & \multicolumn{2}{c}{Result}\ \cmidrule{2-3} & Seaweed isolate & Coral isolate \ \midrule Cell shape & Rod & Rod\ Gram stain & $-$ & $-$\ Oxidase & $+$ & $-$\ Catalase & $+$ & $-$\ MSA & Growth & No growth\ Anaerobic & Growth (weak) & No growth\ Motility & & \ Indole production & & \ Hugh & Leifsons & & \ \bottomrule \end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250
0

An alternative solution with booktabs environment of tabularray package: booktabs and vertical rules work well together.

\documentclass[a4paper,12pt]{article}

\usepackage{tabularray} \UseTblrLibrary{booktabs}

\begin{document}

\begin{booktabs}{@{} l | c | c @{}} \toprule Characteristic & \SetCell[c=2]{c} Result \ \cmidrule{2-3} & Seaweed isolate & Coral isolate \ \midrule Cell shape & Rod & Rod\ Gram stain & $-$ & $-$\ Oxidase & $+$ & $-$\ Catalase & $+$ & $-$\ MSA & Growth & No growth\ Anaerobic & Growth (weak) & No growth\ Motility & & \ Indole production & & \ Hugh & Leifsons & & \ \bottomrule \end{booktabs}

\end{document}

enter image description here

L.J.R.
  • 10,932