How to code tables with multi-line cells

Use the p column descriptor:

Change

\begin{tabular}{lll} 

to

\begin{tabular}{llp{5cm}}

To explicitly insert line-breaks:

CCCCCCCC  & DDDD & \parbox{5cm}{Betty Botter Thought: \\ If I Put This Bitter Butter in My Batter it Will Make My Batter Bitter}

As @aioobe wrote in his answer, in this case one can switch from the left alignment

\begin{tabular}{lll}

to the paragraph alignment, at least in the third column where the custom linebreak must be inserted manually:

\begin{tabular}{llp{.5\textwidth}}

After this edit, one can use the command \par (instead of \newline) to implement the linebreak within the cell.

This code:

\documentclass{article}

\begin{document}

\begin{tabular}{llp{.5\textwidth}}
AAAAAAAAAA & BBBBBBBBBBBBBBB & Betty Botter Bought a Bit of Butter \par but the Butter's Bitter\\
CCCCCCCC & DDDD & Betty Botter Thought: \par If I Put This Bitter Butter in My \par Batter it Will Make My Batter Bitter\\
\end{tabular}

\end{document}

produces the output requested:

screenshot of output


This is the answer I found so far for my needs: Link here.

It creates a new command that will make a table inside a table in a more proper way:

\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}

So, if want to do a forced line break inside a cell like here:

\begin{tabular}{|c|c|c|}
\hline
Foo bar & Foo <forced line break here> bar & Foo bar \\
\hline
\end{tabular}

You will end up using a code like this:

Foo bar & \specialcell{Foo\\bar} & Foo bar \\    % vertically centered
Foo bar & \specialcell[t]{Foo\\bar} & Foo bar \\ % aligned with top rule
Foo bar & \specialcell[b]{Foo\\bar} & Foo bar \\ % aligned with bottom rule

Horizontal alignment can be controlled in the declaration of the new command by changing c@ to l@ or r@

All credit goes to egreg from the Tex forum. Do upvote his answer !

Tags:

Latex

Tabular