How to wrap text in LaTeX tables?
Solution 1:
Use p{width} for your column specifiers instead of l/r/c.
\begin{tabular}{|p{1cm}|p{3cm}|}
This text will be wrapped & Some more text \\
\end{tabular}
EDIT: (based on the comments)
\begin{table}[ht]
\centering
\begin{tabular}{p{0.35\linewidth} | p{0.6\linewidth}}
Column 1 & Column2 \\ \hline
This text will be wrapped & Some more text \\
Some text here & This text maybe wrapped here if its tooooo long \\
\end{tabular}
\caption{Caption}
\label{tab:my_label}
\end{table}
we get:
Solution 2:
With the regular tabular
environment, you want to use the p{width}
column type, as marcog indicates. But that forces you to give explicit widths.
Another solution is the tabularx
environment:
\usepackage{tabularx}
...
\begin{tabularx}{\linewidth}{ r X }
right-aligned foo & long long line of blah blah that will wrap when the table fills the column width\\
\end{tabularx}
All X columns get the same width. You can influence this by setting \hsize
in the format declaration:
>{\setlength\hsize{.5\hsize}} X >{\setlength\hsize{1.5\hsize}} X
but then all the factors have to sum up to 1, I suppose (I took this from the LaTeX companion). There is also the package tabulary
which will adjust column widths to balance row heights. For the details, you can get the documentation for each package with texdoc tabulary
(in TeXlive).
Solution 3:
Another option is to insert a minipage in each cell where text wrapping is desired, e.g.:
\begin{table}[H]
\begin{tabular}{l}
\begin{minipage}[t]{0.8\columnwidth}%
a very long line a very long line a very long line a very long line
a very long line a very long line a very long line a very long line
a very long line a very long line a very long line %
\end{minipage}\tabularnewline
\end{tabular}
\end{table}