1

When using multicolumn the spacing between the columns are not the same. (Column 2 is closer to col 1 than to col 3.) How can I have them the same?

\documentclass{article}
\begin{document}
\begin{tabular}{ccc|c}
\hline
\multicolumn{3}{c|}{Here is a long text} & P \\
 1 & 2 & 3 & $A$ \\
 2 & 1 & 3 & $B$ \\
 3 & 1 & 2 & $C$ \\
 3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\bigskip
\begin{tabular}{ccc|c}
\hline
 & & & P \\
 1 & 2 & 3 & $A$ \\
 2 & 1 & 3 & $B$ \\
 3 & 1 & 2 & $C$ \\
 3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\end{document}
1
  • Simple answer: Without some extra work you can't. That's just how \multicolumn works, it adds any excessive space to the last covered column. Solution coming up quickly would be to use fixed-width columns which you make 1/3 the width of the longest \multicolumn entry covering those 3 lines (minus the width taken by the column separation), but this would be quite some extra manual work.
    – Skillmon
    Dec 22, 2019 at 19:11

1 Answer 1

1

Proof of concept answer for my comment:

\documentclass{article}

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newlength\mylen
\newcommand\seteqwidth[3]
  {%
    \settowidth#1{#2}%
    \setlength#1{\dimexpr(#1-(#3\tabcolsep-\tabcolsep)*2)/#3}%
  }

\begin{document}
\begingroup
\seteqwidth\mylen{Here is a long text}{3}
\begin{tabular}{*3{C{\mylen}}|c}
\hline
\multicolumn{3}{c|}{Here is a long text} & P \\
 1 & 2 & 3 & $A$ \\
 2 & 1 & 3 & $B$ \\
 3 & 1 & 2 & $C$ \\
 3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\endgroup

\bigskip
\begin{tabular}{ccc|c}
\hline
 & & & P \\
 1 & 2 & 3 & $A$ \\
 2 & 1 & 3 & $B$ \\
 3 & 1 & 2 & $C$ \\
 3 & 2 & 1 & $D$ \\
\hline
\end{tabular}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .