Tables – How to Create Vertical Lines in a Table in LaTeX

tables

% 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.

Best Answer

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

Related Question