Search code examples
latextabular

How to code tables with multi-line cells


I am trying to write a short paper with LaTeX and need to add a table with 3 columns.

+-------------+-----------------+--------------------------------------+
| AAAAAAAAAA  | BBBBBBBBBBBBBBB | Betty Botter Bought a Bit of Butter  |
|             |                 | but the Butter's Bitter              |
+-------------+-----------------+--------------------------------------+
| CCCCCCCC    | DDDD            | Betty Botter Thought:                |
|             |                 | If I Put This Bitter Butter in My    |
|             |                 | Batter it Will Make My Batter Bitter |
+-------------+-----------------+--------------------------------------+

Unfortunately I can't seem to find the correct idiom to do it.


I tried:

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

But LaTeX doesn't do any linebreaks or formatting within the cell. I assume I need to tell it to do so.. But how?


Solution

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