1

I have a resized table and want the text in the last row to be wrapped around the full width of this table. How can I set the width p{?} of multicolumn such that this happens?

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{table}
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{llllllllll}
Column A & Column B & Column C & Column D & Column E & Column F & Column G & Column H & Column I & Column J \\
\multicolumn{10}{p{\dimexpr\textwidth-2\tabcolsep\relax}}{
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eu luctus tellus, a faucibus est. Donec id facilisis ipsum. Morbi ac velit magna. Praesent tincidunt egestas ex, ac cursus neque convallis sed. Aenean enim est, feugiat eu velit quis, sodales.
}
\end{tabular}%
}
\end{table}         

\end{document}

Current output: enter image description here

Desired output: enter image description here

  • 1
    Resizing a table using resizebox is generally something I would avoid as it leads to inconsistent and in some cases to illegible small font sizes. – leandriis Jun 15 '18 at 10:41
  • For more consistent font sizes, one could use \centering \footnotesize instead. But as your table is even with a \tiny font size much too wide to fit onto the page, I would suggest to either redesign the table or rotate it on the page. In order to make a tale as wide as the textwidth, tabularx might also be of interest. – leandriis Jun 15 '18 at 10:49
  • Thanks for your considerations. I've tried to reduce the width of the table as much as possible. Redesigning it not the preferred option. Neither is rotating. The actual table is only slightly wider than \textwidth, so the contents are well-legible. Hence a solution to the problem stated above would be best in my case! – woeterb Jun 15 '18 at 11:22
3

You shouldn't resize tables, as it leads to inconsistent font sizes. Use tabularx instead.

As your table has many columns, you might consider loading geometry: unless you use margin notes, you'll have more decent horizontal margins, which make it easier to fit such tables between margins. Here is a simple code:

\documentclass[latin]{article}
\usepackage[showframe]{geometry}
\usepackage{array, makecell, tabularx}
\usepackage{graphicx}
\usepackage{babel}

\begin{document}

\begin{table}[!htb]
\centering
\renewcommand{\theadfont}{\normalsize}
\setlength{\tabcolsep}{4pt}
\begin{tabularx}{\linewidth}{@{}*{10}{>{\arraybackslash}X}@{}}
\thead{Column\\ A} & \thead{Column\\ B} & \thead{Column\\ C} & \thead{Column\\ D} & \thead{Column\\ E} & \thead{Column\\ F} & \thead{Column\\ G} & \thead{Column\\ H} & \thead{Column\\ I} & \thead{Column\\ J}\\
\multicolumn{10}{@{}>{\arraybackslash}p{\textwidth}@{}}{
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eu luctus tellus, a faucibus est. Donec id facilisis ipsum. Morbi ac velit magna. Praesent tincidunt egestas ex, ac cursus neque convallis sed. Aenean enim est, feugiat eu velit quis, sodales.
}
\end{tabularx}%
\end{table}

\end{document} 

enter image description here

If you really need larger margins, you also can play with the font size in the table and the value of \tabcolsep (6pt by default)

0

Apart from the fact that resizing tables is considered bad practice, I found the solution to this problem in this previous answer. The width of the multicolumn spanning all columns will automatically adapt to the width of the table (works also for non-resized tables). The code:

\documentclass{article}

\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{environ}
\newsavebox{\funnytabularbox}
\newlength{\funnytabularwd}

\makeatletter
\NewEnviron{funnytabular}[1]
  {\begin{lrbox}{\funnytabularbox}
   \let\multipar\@gobbletwo
   \begin{tabular}{#1}\BODY\end{tabular}
   \end{lrbox}%
   \setlength{\funnytabularwd}{\wd\funnytabularbox}%
   \addtolength{\funnytabularwd}{-2\tabcolsep}%
   \let\multipar\@multipar
   \begin{tabular}{#1}\BODY\end{tabular}}

\newcommand\@multipar[2]{\multicolumn{#1}{p{\funnytabularwd}}{#2}}
\makeatother

\begin{document}

\begin{table}
\centering
\resizebox{\textwidth}{!}{%
\begin{funnytabular}{llllllllll}
Column A & Column B & Column C & Column D & Column E & Column F & Column G & Column H & Column I & Column J \\
\multipar{10}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eu luctus tellus, a faucibus est. Donec id facilisis ipsum. Morbi ac velit magna. Praesent tincidunt egestas ex, ac cursus neque convallis sed. Aenean enim est, feugiat eu velit quis, sodales.
}
\end{funnytabular}%
}
\end{table}         

\end{document}

Output: 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.