[Tex/LaTex] Dividing long sentence to several lines in table

line-breakingtables

I have a sentence in a table that is too long and makes my table go out of the page. How can I make the sentence divide into several lines so it doesn't ruin the layout of the table?

\begin{table}[!htb]
\caption{}
\centering
\begin{tabular}{llll}
\hline
Material & Production & Description & Reference \\
\hline
 & a bene placito a bene placito a bene placito a bene placito &  & \\
\hline
\end{tabular}
\end{table}

Thanks in advance.

Best Answer

Use p{<width>} for the column that has the long sentence. The width may be in cm, pt or another width that is valid for LaTeX.

\documentclass{article}

\begin{document}
\begin{table}[!htb]
\caption{}
\centering
\begin{tabular}{lp{4cm}ll}
\hline
Material & Production & Description & Reference \\
\hline
 & a bene placito a bene placito a bene placito a bene placito &  & \\
\hline
\end{tabular}
\end{table}
\end{document}

To have a nicer tabular, I suggest loading the array and booktabs packages, and use \toprule, midrule and bottomrule instead of \hline.

p{}-columns are set justified by default, so you may also consider to set the wide column ragged right. Standard LaTeX \raggedright does not hyphenate word, so if your text is very ragged, you need hyphenation in the ragged column. Load the package ragged2e in the preamble and use the command \RaggedRight instead of \raggedright. In your example, you will no see any difference, but try a narrow column with some long words. Here is a modified MWE:

\documentclass{article}
\usepackage{ragged2e,array,booktabs}

\begin{document}
\begin{table}[!htb]
\caption{}
\centering
\begin{tabular}{l>{\RaggedRight}p{4cm}ll}
\toprule
Material & Production & Description & Reference \\
\midrule
 & a bene placito a bene placito a bene placito a bene placito &  & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

Related Question