1

Is there a command to make all columns of the same width? In my example the first two columns are small and the third is much wider. I know that I could have set exact psarameters, but I'm just surprised the columns are not aligned automatically. Thanks in advance!

\documentclass{article}

\begin{document}

\begin{tabular}{|c|c|c|} 
    \hline
    \multicolumn{3}{|c|}{Suppose there's a wide line of text here}  \\
    \hline 
    1 & 2 & 3 \\ %The third line is wider than the rest
    \hline 
\end{tabular}

\end{document}
schtandard
  • 14,892

2 Answers2

1

You can use tabularx, but then you need to set the total width of the tabular:

\documentclass{article}
\usepackage{tabularx}

\begin{document}

\begin{tabularx}{0.7\linewidth}{|X|X|X|} 
        \hline
        \multicolumn{3}{|c|}{Suppose there's a wide line of text here}  \\
        \hline 
        1 & 2 & 3 \\ %The third line is wider than the rest
        \hline 
    \end{tabularx}
\end{document}

enter image description here

Sveinung
  • 20,355
0

Welcome to TeX SX! That is because the standard r,l,c specifiers are for one-line content, and your first row natural length is much wider than the sum of the natural lengths of the columns in the second row. You can either use one of thep, m or X column types, or load makecell and use the eponymous command for the 1st row: it allows for line breaks in standard cells.

Here is an (exaggerated) example of this last solution:

\documentclass{article}
\usepackage{makecell} 

\begin{document}

\begin{tabular}{|c|c|c|}
    \hline
    \multicolumn{3}{|c|}{\makecell{Suppose\\ there's a\\ wide line\\ of text \\here}} \\
    \hline
    1 & 2 & 3 \\ %The third line is wider than the rest
    \hline
\end{tabular}

\end{document} 

enter image description here

Bernard
  • 271,350