5
% Table generated by Excel2LaTeX from sheet 'paper2'
\begin{table}[htbp]
  \centering
  \caption{Comparison of the CCSHR estimators based on beta and logit-normal distributions}
    \begin{tabular}{cc|ccc|ccc}
\toprule
      &       & \multicolumn{3}{c}{CCSHR\_11} & \multicolumn{3}{c}{CCSHR\_12} \\
\midrule
\multicolumn{1}{c}{mu} & \multicolumn{1}{c}{sigma} & Beta  & Logit-normal & TRUE  & Beta  & Logit-normal & TRUE \\ \hline
\multicolumn{1}{c}{0} & \multicolumn{1}{c}{0.33} & 2.099 (0.134) & 2.106 (0.170) & 2.053 & 1.918 (0.129) & 1.915 (0.132) & 1.947 \\
\multicolumn{1}{c}{0} & \multicolumn{1}{c}{1.00} & 2.359 (0.170) & 2.348 (0.187) & 2.347 & 1.665 (0.134) & 1.677 (0.143) & 1.653 \\
(many lines omitted)
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%

enter image description here

Here are my LaTeX code for a table and the result. I intended to add vertical lines between the 2nd and 3rd columns and between 5th and 6th columns. But the 1st vertical line appears only in the 1st row and the 2nd vertical line is shown in the 2nd row and beyond. How can I modify these TeX code so that I can see both vertical lines at all rows?

This code is generated from Excel2LaTeX add-in.

  • 2
    Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Do you mena that you don't understand the code of the table generated? – Aradnix Aug 29 '14 at 2:10
  • 5
    The output uses the booktabs package. And if you read the booktabs documentation you will see it mentions to "Never, ever use vertical rules." Through spacing one can provide sufficient dividers and groups within the table. – Werner Aug 29 '14 at 2:31
13

Your table is wider than the text width. Those `\multicolumn{1}{c}{..} are all redundant, hence you can remove them. With these, your table becomes

\documentclass{article}
\usepackage{booktabs}
\begin{document}
  % Table generated by Excel2LaTeX from sheet 'paper2'
\begin{table}[htbp]
  \caption{Comparison of the CCSHR estimators based on beta and logit-normal distributions}
\makebox[\textwidth][c]{
    \begin{tabular}{cc|ccc|ccc}
\toprule
      &       & \multicolumn{3}{c|}{CCSHR\_11} & \multicolumn{3}{c}{CCSHR\_12} \\
\midrule
mu & sigma & Beta  & Logit-normal & TRUE  & Beta  & Logit-normal & TRUE \\ \hline
0 & 0.33 & 2.099 (0.134) & 2.106 (0.170) & 2.053 & 1.918 (0.129) & 1.915 (0.132) & 1.947 \\
0 & 1.00 & 2.359 (0.170) & 2.348 (0.187) & 2.347 & 1.665 (0.134) & 1.677 (0.143) & 1.653 \\
\bottomrule
\end{tabular}%
}
\label{tab:addlabel}%
\end{table}%
\end{document}

enter image description here

I have centered the table using \makebox.

As the saying goes, why to use vertical lines at all? Here is an improved version:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
  % Table generated by Excel2LaTeX from sheet 'paper2'
\begin{table}[htbp]
  \caption{Comparison of the CCSHR estimators based on beta and logit-normal distributions}
\makebox[\textwidth][c]{
    \begin{tabular}{cccccccc}
\toprule
      &       & \multicolumn{3}{c}{CCSHR\_11} & \multicolumn{3}{c}{CCSHR\_12} \\
\cmidrule(lr){3-5}\cmidrule(lr){6-8}
mu & sigma & Beta  & Logit-normal & TRUE  & Beta  & Logit-normal & TRUE \\ \midrule
0 & 0.33 & 2.099 (0.134) & 2.106 (0.170) & 2.053 & 1.918 (0.129) & 1.915 (0.132) & 1.947 \\
0 & 1.00 & 2.359 (0.170) & 2.348 (0.187) & 2.347 & 1.665 (0.134) & 1.677 (0.143) & 1.653 \\
\bottomrule
\end{tabular}%
}
\label{tab:addlabel}%
\end{table}%
\end{document}

enter image description here

5

As has been mentioned in the comments, the first rule of the booktabs documentation is to never use vertical rules.

Here's an improvement that features:

  • use of the siunitx package for formatting numbers and uncertainties in tabular material,
  • no vertical rules, instead using white space and \cmidrules with trimmed sides to show the grouping, and
  • slight adjustments to \tabcolsep and \cmidrulekern to fit the table in the text width.

Commented Code:

\documentclass{article} 
\usepackage{booktabs,siunitx}
\setlength{\abovetopsep}{0.5em} % provide space between caption and top rule

\begin{document}
\begin{table}[tbp] % don't use ! as it *ignores* LaTeX's best choice!
\centering
\setlength{\tabcolsep}{3.7pt}     % slight adjustment to fit text width
\setlength{\cmidrulekern}{0.25em} % adjust for decreased col sep
\caption{Comparison of the CCSHR estimators based on beta and logit-normal distributions}
\begin{tabular}{%
  S[table-format=1.0]
  S[table-format=1.2]
  *{2}{ % we need 2 copies of the below sequence
    *{2}{S[table-format=1.3(3)]} % number of digits in the column; form: numbers.decimals(uncertainty)
    S[table-format=1.3]
  }
}
  \toprule
  & & \multicolumn{3}{c}{CCSHR\_11}     
    & \multicolumn{3}{c}{CCSHR\_12}    \\
    \cmidrule(lr){3-5}                  
    \cmidrule(lr){6-8}
  {$\mu$} & {$\sigma$} & {Beta} & {Logit-normal} & {TRUE}  % protect text headers with braces
                       & {Beta} & {Logit-normal} & {TRUE} \\
  \midrule
  0 & 0.33 & 2.099 \pm 0.134 & 2.106 \pm 0.170 & 2.053 & 1.918 \pm 0.129 & 1.915 \pm 0.132 & 1.947 \\
  0 & 1.00 & 2.359 \pm 0.170 & 2.348 \pm 0.187 & 2.347 & 1.665 \pm 0.134 & 1.677 \pm 0.143 & 1.653 \\
  %(many lines omitted)
  \bottomrule
\end{tabular}
\label{tab:addlabel}
\end{table}
\end{document}

Output:

enter image description here

Other Notes: I'm not sure about the lines you omitted, but if μ is 0 for every row in a particular table, you could remove that column and write $\mu=0$ somewhere in the headers or caption instead. This would save some space, reducing or eliminating the required adjustments to \tabcolsep (default 6pt) and \cmidrulekern (default 0.5em).

3

Something like this? Forgot to put a vertical line in, for example, \multicolumn{1}{c|}{sigma} where you need the lines to appear.

enter image description here

Code

\documentclass{article} 
    \usepackage{array}
    \usepackage{graphicx} 
    \usepackage{multirow}
    \usepackage{hhline,booktabs,amsmath}
    \usepackage{makecell}

\begin{document}
\begin{table}[!htbp]
  \centering
\caption{Comparison of the CCSHR estimators based on beta and logit-normal distributions}
\begin{tabular}{cc|ccc|ccc}
\toprule
      &       & \multicolumn{3}{c|}{CCSHR\_11} & \multicolumn{3}{c}{CCSHR\_12} \\
\midrule
\multicolumn{1}{c}{mu} & \multicolumn{1}{c|}{sigma} & Beta  & Logit-normal & TRUE  & Beta  & Logit-normal & TRUE \\ \hline
\multicolumn{1}{c}{0} & \multicolumn{1}{c|}{0.33} & 2.099 (0.134) & 2.106 (0.170) & 2.053 & 1.918 (0.129) & 1.915 (0.132) & 1.947 \\
\multicolumn{1}{c}{0} & \multicolumn{1}{c|}{1.00} & 2.359 (0.170) & 2.348 (0.187) & 2.347 & 1.665 (0.134) & 1.677 (0.143) & 1.653 \\
%(many lines omitted)
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.