Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need a table with 4 rows, 3 columns and a partial horizontal line in column 2-3. I tried:

\documentclass{article}

\begin{document}

\begin{table}
{
 \begin{center}
\begin{tabular}{|c|c|c|}
\hline
Col 1 & \multicolumn{2}{|c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{center}
}
\end{table}     

\end{document}

which yielded:

Note that, width of column 2 & 3 are not equal. How can I fix that?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

If the width of the contents of a spanned cell produced using \multicolumn is larger then the width of the contents of the individual cells, the extra space is added to the last spanned column, as you have experienced and this example shows even clearer:

\documentclass{article}

\begin{document}

\noindent\begin{tabular}{|c|c|c|c|}
\hline
A & \multicolumn{3}{c|}{Some text just for the example} \\
\hline
B & C & D & E \\
\hline
\end{tabular}

\end{document}

enter image description here

Two options: you can change to centered p{...} columns (the two options show this same approach with and without the tabularx package):

\documentclass{article}
\usepackage{tabularx}

\newcolumntype{C}{>{\centering\arraybackslash}p{1.5cm}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|c|c|c|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{table}     

\begin{table}
\centering
\begin{tabular}{|C|C|C|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabular}
\end{table}     

\begin{table}
\centering
\begin{tabularx}{6cm}{|Y|Y|Y|}
\hline
Col 1 & \multicolumn{2}{c|}{Col 2-3 Heading}\\
\cline{2-3} & Col 2 & Col 3\\
\hline
- & - & -\\
\hline
- & - & - \\
\hline
- & - & - \\
\hline
\end{tabularx}
\end{table}     

\end{document}

enter image description here

Not related to the question: inside a float is better to use \centering and not the center environment; the later adds extra vertical space which most of the times is undesired.

share|improve this answer
    
It worked, but can you explain why is this happening? –  pushpen.paul Mar 15 at 19:26
    
@pushpen.paul yes, it's a well known phenomenon. I'll add the explanation in some minutes (lunch time here). –  Gonzalo Medina Mar 15 at 19:27
    
@pushpen.paul explanation added. –  Gonzalo Medina Mar 15 at 19:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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