Sarmate.net Sarmate.net
Home Features Pricing Documentation Contact
Log in Sign up

Tables

Tables are made with the tabular environment. The trick: you first describe the columns (l, c, r for left-aligned, centred, right-aligned), then fill them in — & separates the cells, \\ ends a row.

Compile Compile this two-column table. Notice {l c} (two columns), & (separator) and \\ (end of row).

Adding a column

For one more column: add a letter in {...} and a cell (& …) on each row.

Modify Your turn: add a 3rd column “Honours”. Remember {l c c} and an & … on each row. Compile.
Show the solution
\documentclass{article}
\begin{document}
\begin{tabular}{l c c}
  \hline
  Student & Grade & Honours \\
  \hline
  Alice & 17 & Distinction \\
  Bob & 14 & Merit \\
  \hline
\end{tabular}
\end{document}
Fix This table does not compile: one row has too many cells for its 2 columns. Fix it (remove the extra cell, or declare a 3rd column), then compile.
Show the solution
\documentclass{article}
\begin{document}
\begin{tabular}{l c}
  Alice & 17 \\
  Bob & 14 \\
\end{tabular}
\end{document}
Without counting the &: build your table visually (like a spreadsheet) and retrieve the LaTeX code. Open the table editor →
Key takeaway: tabular{...} describes the columns; & separates the cells; \\ ends the row; \hline draws a rule. As many cells per row as declared columns.