The makecell package

Provides \makecell for line breaks inside a table cell and \thead for column headings with their own font.

Loading the package

\usepackage{makecell}

In an l, c or r column, \\ ends the table row; a cell cannot hold two lines. \makecell{first \\ second} builds a small one-column table inside the cell, so \\ breaks the line there. An optional argument sets the alignment: l, c or r horizontally, t or b vertically.

\thead does the same for heading cells and sets them in the font \theadfont. The package also has \Xhline for a horizontal line of any thickness and \makegapedcells for more space above and below the cell content. It loads array.

Main commands

\makecell{first run \\ second run}Cell with two centred lines.
\makecell[l]{left \\ aligned}Left-aligned lines; [tl] also aligns the cell with the top of the row.
\thead{Measured \\ value}Heading cell with a line break, set in \theadfont.
\renewcommand{\theadfont}{\bfseries}Font of all \thead cells; the default is \footnotesize.
\Xhline{1pt}Horizontal line with a thickness of 1 pt.
\multirowcell{2}{two \\ lines}Cell with line breaks across 2 rows; needs multirow.
\setcellgapes{4pt}\makegapedcellsAdds 4 pt above and below the content of every cell in the tables that follow.

Complete example

\documentclass{article}
\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}
\begin{document}
\begin{tabular}{lcr}
\Xhline{1pt}
\thead{Sample} & \thead{Measured \\ value} & \thead{Unit} \\
\hline
A & \makecell{first run \\ second run} & mm \\
B & \makecell[l]{left-aligned \\ lines} & cm \\
C & one line & m \\
\Xhline{1pt}
\end{tabular}
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages