1

I'm dealing with an aesthetic issue related to a multicolumn in a table.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\caption{Large Width Table}\label{ch1tab:rev}
%\renewcommand{\arraystretch}{1.3}

\begin{tabular}{|c|c|}
    \toprule
    \multicolumn{2}{c}{\textbf{RandomTextRandomText}} \\ %\cline{3-4}
    $t_1$                     & $t_1$     \\\midrule
    1&1\\
    1&1\\
    1&1 \\ \bottomrule
    \multicolumn{2}{c}{Lorem ipsum dolor sit amet, consectetur adipiscing elit}
\end{tabular}
\end{table}

\end{document}

The problem is that the width of the multicolumn (in this case of the whole table) is larger than the sum of the subcolumn and thus all the excessive width is put in the last subcolum.

enter image description here

From some answers it seems that I should force the width of the subcolumn to be greater than the one of the multicolumn. Is there a more elegant and automatic solution?

Thank you

1
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\newsavebox\TBox
\begin{document}

\begin{table}
\sbox\TBox{Lorem ipsum dolor sit amet, consectetur adipiscing elit}
\centering
\caption{Large Width Table}\label{ch1tab:rev}
\begin{tabular}{|>{\centering}p{0.5\wd\TBox}|c|}\toprule
    \multicolumn{2}{c}{\bfseries RandomTextRandomText} \\ %\cline{3-4}
    $t_1$                     & $t_1$     \\\midrule
    1&1\\
    1&1\\
    1&1 \\ \bottomrule
\multicolumn{2}{c}{Lorem ipsum dolor sit amet, consectetur adipiscing elit}\\
\end{tabular}
\end{table}

\end{document}

enter image description here

  • why you measure some text not contained in table? your answer is not very consistent. read my comment below question ... – Zarko May 14 at 17:59
  • The Lorem ipsum ... is the last row in OP's table and wider than the Random Text Random Text. – Henk Metselaar May 15 at 7:27
1

Let convert my comment to the answer:

\documentclass{article}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newsavebox\TB  % Table Box
\newlength\wdTB % width of TB

\usepackage{lipsum}
\begin{document}
\lipsum[11]
    \begin{table}[htb]
\sbox{\TB}{\textbf{Random Text Random Text}}
\setlength{\wdTB}{\wd\TB}
    \centering
\caption{Large Width Table}
\label{ch1tab:rev}
\begin{tabular}{|*{2}{>{\centering\arraybackslash}p{0.5\wdTB}|}}
    \hline
    \multicolumn{2}{|c|}{\usebox{\TB}}  \\
    \hline
    $t_1$   &   $t_1$   \\
    \hline
    1       &   1       \\
    1       &   1       \\
    1       &   1       \\
    \hline
\multicolumn{2}{p{\wdTB}}{Is this some comment to table contents?}
\end{tabular}
    \end{table}
\lipsum[12]
    \begin{table}[htb]
    \centering
\caption{Large Width Table}
\label{ch1tab:rev}
\begin{tabular}{|*{2}{C{15mm}|}}
    \hline
    \multicolumn{2}{|C{\dimexpr15mm+15mm+2\tabcolsep}|}{\textbf{Random Text Random Text}}  \\
    \hline
    $t_1$   &   $t_1$   \\
    \hline
    1       &   1       \\
    1       &   1       \\
    1       &   1       \\
    \hline
\multicolumn{2}{p{\dimexpr30mm+2\tabcolsep}}{Is this some comment to table contents?}
\end{tabular}
    \end{table}
\end{document}

first table use measurement of multicolumn cell, the second break content of this cell that it is not wider than sum of the spanned columns:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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