0

I have seen some related questions but I could not find a minimal reproducible example that helps in my basic case.

Let us say I have a simple table with a multicolumn. The code is as follows

\documentclass[a4paper]{article}

\begin{document}
\begin{table}

\begin{tabular}{| c |  c |}
\multicolumn{2}{|c|}{Header text}\\
A & B\\
C & D\\
\end{tabular}

\end{table}
\end{document}

and this is the output

I would expect A, B, C, D to be horizontally centered, but they are not. What is the simplest way to achieve this?

MathMax
  • 113
  • as is more clear after your edit where you added the lines, A and B are centred in their columns, but the second column gets all the extra width from the heading as if span is wider than the columns it spans all the extra width goes to the last spanned column. so it is a column width issue not an alignment one. (simplest is perhaps to use tabular* – David Carlisle Mar 12 '20 at 10:44
  • @DavidCarlisle Thank you, I did not notice this related question. It looks like it takes a lot of code to achieve my simple desired output though. As for the duplicated question, would you suggest I delete this one? – MathMax Mar 12 '20 at 10:55
  • no duplicates are OK (actually help people search, I'll vote is as dup) – David Carlisle Mar 12 '20 at 10:59
  • note the related links also has https://tex.stackexchange.com/questions/95309/table-column-widths-disproportionate-due-to-multicolumn-cell-being-too-long?rq=1 – David Carlisle Mar 12 '20 at 11:00
  • @DavidCarlisle in the link you posted you provide four alternative solutions, none of which does exactly what I want. The last solution is the closest to what I want, except that the table takes all the horizontal space available in the document. I want the width to depend on the contents of the table instead. Any advice on this? I understand that simple behaviours might be cumbersome to implement in LaTeX. Which is probably why you developed a whole library on tables (much appreciated). – MathMax Mar 12 '20 at 11:12
  • The underlying behaviour of the tex \halign with spanned cells is really unhelpful here so "doing what you want" and "staying vaguely compatible with existing latex table macros" is harder than you might hope. – David Carlisle Mar 12 '20 at 11:23

0 Answers0