# \multicolumn table cell doesn't fit page width

I have this code:

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\begin{tabular}{ |c|c| }
\hline
\multicolumn{2}{|c}{\lipsum[1]}\\
\hline
text text text text text text & text text text text\\
\hline
\end{tabular}
\end{document}


It generates this:

How to make top cell fit the page size, like with X column format?

Here is the code, based upon Mico's example. It creates a page-wide table with a column to the left of multicolumn. (The adjustment of 1.2pt is there to account for the three vertical lines, each 0.4pt wide, that contribute to the total width of the tabularx environment.)

\documentclass{article}
\usepackage{lipsum,tabularx,calc,fullpage}
\newcolumntype{Y}{>{\centering\arraybackslash}X} % centered version of "X" column type
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|p{3cm}|Y|Y|}
\hline
text text text text text &
\multicolumn{2}{p{\dimexpr\textwidth -1.2pt - 4\tabcolsep-3cm}|}{\lipsum[1]}\\
\hline
&text text text text text text & text text text text\\
\hline
\end{tabularx}
\end{document}

• You don't have line-breaking with c-type columns. Replace c by p{\textwidth} in the \multicolumn command. – jub0bs Mar 26 '13 at 16:53

## 1 Answer

You could use the tabularx package and its eponymous tabularx environment. The only tricky part is how to get the width of the 2-column term: To calculate the allowable width, you have to subtract from \textwidth the following items: 2\tabcolsep, to account for the whitespace at the left and right hand edges, and 0.8pt (=2*0.4pt), for the widths of the two vertical lines.

\documentclass{article}
\usepackage{lipsum,tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X} % centered version of "X" column type
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|c|Y|}
\hline
\multicolumn{2}{|p{\dimexpr\textwidth-2\tabcolsep-0.8pt}|}{\lipsum[2]}\\
\hline
text text text text text text & text text text text\\
\hline
\end{tabularx}
\end{document}


Addendum: If you want the two columns to have equal width (and still have their contents centered), just replace the c with a Y in the second argument of the tabularx specification:

• How to correctly find the width when we have another column to the left of \multicolumn top cell? – user4035 Mar 26 '13 at 17:09
• @user4035 - Please be a bit more specific about the type of columns that might be to the left of the p column: Would this be fixed-width column (such as another p column), or some other type? – Mico Mar 26 '13 at 17:19
• A fixed width column. I made it work, look at the question edit. But is it possible to get rid of the hard coded values? – user4035 Mar 26 '13 at 19:48
• @user4035 - I've edited both your augmented example as well as my own MWE to adjust for the widths of the vertical lines; each such line is 0.4pt wide... – Mico Mar 26 '13 at 22:12