Align text in table cells in LaTeX (horizontal and vertical)
The letters l, c and r in the column argument align a column left, centered or right. For the vertical position, the array package adds m{width} (middle) and b{width} (bottom) to the standard p{width} (top).
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{array}Align a whole column
Each letter in the column argument stands for one column. Numbers usually go into an r column so that their digits line up.
\begin{tabular}{lcr}
\hline
left & centered & right \\
Apple & red & 0.50 \\
Watermelon & green & 12.00 \\
\hline
\end{tabular}Align a single cell differently
\multicolumn{1}{c}{text} replaces the alignment of the column for this one cell. A typical use is a centered header above a right-aligned column of numbers.
\begin{tabular}{lr}
\hline
Item & \multicolumn{1}{c}{Price} \\
\hline
Apple & 0.50 \\
Watermelon & 12.00 \\
\hline
\end{tabular}Align text in a fixed-width column
A p{3cm} column is justified. >{\centering\arraybackslash} in front of it centers the text, \raggedleft moves it to the right and \raggedright to the left without justification.
\begin{tabular}{|>{\raggedright\arraybackslash}p{3cm}|>{\centering\arraybackslash}p{3cm}|>{\raggedleft\arraybackslash}p{3cm}|}
\hline
left, ragged right & centered in three centimeters & right \\
\hline
\end{tabular}Align cells vertically
The column type decides which line of a cell with several lines stands level with the other cells of the row: the first line with p{4cm}, the vertical center with m{4cm} and the last line with b{4cm}. In this example "Label" and "end" stand next to the middle of the text.
\begin{tabular}{|l|m{4cm}|l|}
\hline
Label & This cell holds a longer text that takes three lines in a column of this width. & end \\
\hline
\end{tabular}Pitfalls
\centering,\raggedrightand\raggedleftchange the meaning of\\. Without\arraybackslashin the last column,\\no longer ends the row and the next row stops with Extra alignment tab has been changed to \cr.- To align numbers with different numbers of decimals, see Align numbers at the decimal point in LaTeX tables.
Compiled with pdfLaTeX from TeX Live 2023.