Line break in a table cell in LaTeX (makecell, newline)
In an l, c or r column, \\ ends the table row, not the line in the cell. Wrap the cell in \makecell{first \\ second} from the makecell package, or use a p{width} column, where \newline breaks the line.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{makecell}Break lines with makecell
Inside \makecell{...}, \\ starts a new line of the cell. The lines are centered; the optional argument changes that: \makecell[l]{...} aligns them left, \makecell[r]{...} right. \thead{...} does the same for header cells and sets them in a smaller font.
\begin{tabular}{|l|l|}
\hline
\thead{Name} & \thead{Postal \\ address} \\
\hline
Anna & \makecell[l]{12 Main Street \\ Springfield} \\
\hline
\end{tabular}Break lines in a p column
A p{4cm} column wraps long text by itself. \newline forces a break at a chosen place.
\begin{tabular}{|l|p{4cm}|}
\hline
Name & Address \\
\hline
Anna & 12 Main Street \newline Springfield \\
\hline
\end{tabular}Break lines without a package
A small tabular inside the cell also holds several lines. @{} on both sides of its column letter removes the padding, so the inner text lines up with the other cells, and [t] puts its first line level with the row.
\begin{tabular}{|l|l|}
\hline
Name & Address \\
\hline
Anna & \begin{tabular}[t]{@{}l@{}}12 Main Street \\ Springfield\end{tabular} \\
\hline
\end{tabular}Pitfalls
\newlinedoes not break the line in anl,corrcolumn. These columns never hold more than one line unless the cell contains a box such as\makecell.- In a
pcolumn a plain\\ends the table row as well. Use\newlinefor the break inside the cell.
Compiled with pdfLaTeX from TeX Live 2023.