3

I have some table

\begin{table}
\begin{tabularx}{\textwidth}{Xrr}
A  & B  & C  \\
\multicolumn{3}{p{XXX}}{Test}
\end{tabularx}
\end{table}

where the second row should span the entire table width. I wonder what needs to replace XXX in p{XXX}.

0

1 Answer 1

3

With \begin{tabularx}{\textwidth} you declare a table that is as wide as the textwidth. For the width of the multicolumn you can load the calc package and use \textwidth-2\tabcolsep (2\tabcolsep to account for the small horizontal white space to the left and right of each cell):

enter image description here

\documentclass{article}
\usepackage{calc}
\usepackage{tabularx}

\usepackage{lipsum}
\begin{document}
\lipsum[4]

\begin{table}
\begin{tabularx}{\textwidth}{Xrr}
A  & B  & C  \\
\multicolumn{3}{p{\textwidth-2\tabcolsep}}{some long text in this column some long text in this column some long text in this column some long text in this column some long text in this column}
\end{tabularx}
\end{table}

\end{document}
3
  • Unfortunately, this yields the error Missing number, treated as zero. < to be read again > \relax l.786 \end{tabularx}. I don't see what is different from the MWE in my application.
    – bumblebee
    Mar 11, 2020 at 22:03
  • 3
    @bumblebee - Did you load the calc package? If not, you should replace p{\textwidth-2\tabcolsep} with p{\dimexpr\textwidth-2\tabcolsep\relax}.
    – Mico
    Mar 11, 2020 at 22:05
  • Excellent, this works! Amended the answer to clarify this beyond the MWE.
    – bumblebee
    Mar 11, 2020 at 22:10

You must log in to answer this question.

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