0

I have a table that I want to span the page (to be consistent with the other tables I have) but this table has vertical lines in it and making the table span the page gives vertical lines that aren't centered:

uncentered

How can I make it so the vertical lines are horizontally centered between the columns that they separate? Removing the lines isn't an option, and I'd prefer to not use a different package (if possible).

\documentclass{article}
\RequirePackage[top=2.54cm, bottom=2.54cm, left=3.05cm, right=2.54cm]{geometry}
\usepackage{booktabs}

\begin{document}

\newcommand{\mlc}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}%  http://tex.stackexchange.com/a/19678

\begin{table}[t]
\centering
\caption{a table with uncentered vertical lines }
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}cc|ccc||c} % 
\toprule 
\multicolumn{2}{c}{ } & \multicolumn{4}{c}{cut-off} \\ \cline{3-6} \\
\mlc{Various stuff\\(MeV)} & \# of data & A & B & C & \mlc{Ref. [bleh] \\ at B } \\ 
\midrule
$np$ &&&&&\\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\midrule
$pp$ &&&&&\\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\bottomrule 
\end{tabular*}
\end{table}

\end{document}
Status
  • 113
  • Vertical lines in with booktabs? ;-) –  Dec 02 '15 at 18:49
  • 1
    Package booktabs assume, that table hasn't vertical lines. For table design is worth to watch http://wiert.me/2014/04/03/andre-vatter-google-wie-tabellen-eigentlich-aussehen-sollten-%EF%BB%BF/ .... – Zarko Dec 02 '15 at 18:50
  • @Zarko You're welcome to argue with the professor who insisted the vertical lines be there (hint: it won't work). – Status Dec 02 '15 at 18:55
  • 1
    :-), with pleasure ... :-), but be serious, if you forced to stick with vertical lines, then don't use booktabs. Result i, as you can see yourself, is really terrible. And vertical lines are on the border of columns, so they per se can not be centered – Zarko Dec 02 '15 at 19:01

2 Answers2

1

The best (to my knowledge) can be done is:

enter image description here

Do this design your professor liked? For above table I use packages makecell, multirow and tabu:

\documentclass{article}
    \usepackage[top=2.54cm, bottom=2.54cm, left=3.05cm, right=2.54cm]{geometry}
    \usepackage{makecell,multirow,tabu}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\newcommand\mrc[2]{\multirowcell{#1}[0pt][c]{#2\strut}}

    \begin{document}
%---------------------------------------------------------------%
    \begin{table}
    \abovetabulinesep=2mm
    \belowtabulinesep=2mm
\begin{tabu}to \linewidth   {*2{X[1,c]}|*3{X[1,c]}||X[1,c]}
    \tabucline[1.5pt]{-}
        & \mc{}  &   \multicolumn{4}{c}{cut-off}                    \\
    \tabucline {3-6}
\mrc{1}{Various stuff\\(MeV)}       
        & \# of data          
                 & \mc{A} & B & C & \mrc{1}{Ref. [bleh] \\ at B }   \\
    \tabucline[1pt] {-}
$np$    &&&&&                                                       \\
0 - 100 & number & value & value  & value & value \\
0 - 190 & number & value & value  & value & value \\
    \tabucline {-}
$pp$    &&&&&                                   \\
0 - 100 & number & value & value  & value & value \\
0 - 190 & number & value & value  & value & value \\
    \tabucline[1.5pt]{-}
    \end{tabu}
\end{table}
    \end{document}
Zarko
  • 296,517
1

I propose this code, using tabularx and makecell. Makecell allows for line breaks in tabular cells, vertical padding of cell with the \setcellgapes and \makegapedcells command, and lines with variable thickness. I was not sure whether you want vertical lines in the second row. They're easy to add if you need them. Also, I loaded captionfor a correct vertical spacing between caption and table.

\documentclass{article}
\RequirePackage[vmargin=2.54cm, left=3.05cm, right=2.54cm]{geometry}
\usepackage{caption}
\usepackage{makecell, tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}
\setcellgapes{3pt}


\begin{document}

\begin{table}[t]
  \centering
  \makegapedcells
  \caption{a table with centred vertical lines }
  \begin{tabularx}{\linewidth}{XX|XXX||X} %
    \Xhline{0.08em}\noalign{\vskip1ex}
    \multicolumn{2}{c}{} & \multicolumn{4}{c}{cut-off} \\[1ex]
    \Xcline{3-6}{0.05em}
    \makecell{Various stuff \\(MeV)} & \multicolumn{1}{c}{\# of data} & A & B & \multicolumn{1}{c}{C} & \makecell{Ref. [bleh] \\ at B } \\
    \Xhline{0.05em}
    $np$ & & & & & \\
    0 - 100 & number & value & value & value & value \\
    0 - 190 & number & value & value & value & value \\
    \Xhline{0.05em}
    $pp$ & & & & & \\
    0 - 100 & number & value & value & value & value \\
    0 - 190 & number & value & value & value & value \\
    \Xhline{0.08em}
  \end{tabularx}
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350