[Tex/LaTex] \multicolumn table cell doesn’t fit page width

multicolumntables

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:

enter image description here

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}

Best 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}

enter image description here

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:

enter image description here