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

Creating tables in LaTeX

LaTeX tables allow you to present data in a structured way. This guide covers the tabular environment, borders, cell merging, and packages for more elaborate tables.

Create your tables visually
Colors, borders, cell merging, formulas — our editor generates the LaTeX code automatically.
Open the editor

Basic table with tabular

The tabular environment is the foundation of tables in LaTeX:

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\begin{tabular}{l c r}
    Left & Center & Right \\
    A      & B      & C      \\
    1      & 2      & 3      \\
\end{tabular}

\end{document}

Column specifiers

Specifier Alignment
l Left-aligned
c Centered
r Right-aligned
p{width} Fixed-width paragraph (automatic line wrapping)
| Vertical line

Adding borders

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\begin{tabular}{|l|c|r|}
    \hline
    Name    & Age & City    \\
    \hline
    Alice  & 25  & London    \\
    Bob    & 30  & Manchester     \\
    Claire & 28  & Bristol \\
    \hline
\end{tabular}

\end{document}
  • | in column definition: vertical lines
  • \hline: full horizontal line
  • \cline{i-j}: partial horizontal line (columns i to j)

Professional tables with booktabs

The booktabs package creates more elegant tables, without vertical borders:

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{lcc}
    \toprule
    Product  & Price   & Quantity \\
    \midrule
    Apples   & 2.50   & 100      \\
    Oranges  & 3.00   & 80       \\
    Bananas  & 1.80   & 150      \\
    \bottomrule
\end{tabular}

\end{document}
Best practice Typographic style guides recommend using booktabs and avoiding vertical borders for more readable tables.

Merging cells

Horizontal merging (multicolumn)

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\begin{tabular}{|l|c|c|}
    \hline
    \multicolumn{3}{|c|}{Title across 3 columns} \\
    \hline
    Name & Grade 1 & Grade 2 \\
    \hline
    Alice & 15 & 17 \\
    Bob   & 12 & 14 \\
    \hline
\end{tabular}

\end{document}

Syntax: \multicolumn{count}{alignment}{content}

Vertical merging (multirow)

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|l|c|c|}
    \hline
    \multirow{2}{*}{Category} & \multicolumn{2}{c|}{Results} \\
    \cline{2-3}
                               & 2023 & 2024 \\
    \hline
    Sales                     & 100  & 120  \\
    Profits                    & 20   & 25   \\
    \hline
\end{tabular}

\end{document}

Syntax: \multirow{count}{width}{content} (use * for automatic width)

The table environment

As with figures, use table to add a caption and a number:

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{booktabs}

\begin{document}

\begin{table}[htbp]
    \centering
    \caption{Experiment results}
    \label{tab:resultats}
    \begin{tabular}{lcc}
        \toprule
        Variable & Group A & Group B \\
        \midrule
        Mean  & 42.3     & 38.7     \\
        Std. dev. & 5.2    & 4.8      \\
        \bottomrule
    \end{tabular}
\end{table}

Table~\ref{tab:resultats} shows the results.
\end{document}

Controlling width

Fixed-width columns

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

% Column with automatic line wrap\begin{tabular}{|l|p{5cm}|}
    \hline
    Title & Long description that will automatically wrap to the next line \\
    \hline
\end{tabular}

\end{document}

Full-width table

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tabularx}

\begin{document}

% X = column that expands to fill available space\begin{tabularx}{\textwidth}{|l|X|c|}
    \hline
    Name & Description & Price \\
    \hline
    Product A & Detailed description that adapts automatically & 10 \\
    \hline
\end{tabularx}

\end{document}

Colors in tables

LaTeX
\usepackage[table]{xcolor}  % In the preamble
% Colored row
\rowcolor{gray!20}

% Colored cell
\cellcolor{blue!10}

% Automatically alternating rows
\rowcolors{2}{gray!10}{white}
\begin{tabular}{lcc}
    \toprule
    A & B & C \\
    \midrule
    1 & 2 & 3 \\
    4 & 5 & 6 \\
    7 & 8 & 9 \\
    \bottomrule
\end{tabular}

Complete example

LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[table]{xcolor}

\begin{document}

\section{Sales report}

\begin{table}[htbp]
    \centering
    \caption{Sales by region and quarter (in thousands)}
    \label{tab:ventes}
    \rowcolors{2}{gray!10}{white}
    \begin{tabular}{lrrrr}
        \toprule
        \textbf{Region} & \textbf{Q1} & \textbf{Q2} & \textbf{Q3} & \textbf{Q4} \\
        \midrule
        North            & 150         & 180         & 165         & 200         \\
        South             & 120         & 140         & 135         & 155         \\
        East             & 90          & 110         & 105         & 125         \\
        West           & 130         & 145         & 140         & 170         \\
        \midrule
        \textbf{Total}  & \textbf{490} & \textbf{575} & \textbf{545} & \textbf{650} \\
        \bottomrule
    \end{tabular}
\end{table}

Table~\ref{tab:ventes} shows consistent growth in the fourth quarter.
\end{document}

Sign and variation tables (tkz-tab)

The tkz-tab package makes it easy to create sign and variation tables, commonly used in mathematics.

Save time with our visual editor
Build your sign and variation tables in just a few clicks — the LaTeX code is generated automatically. No need to write tkz-tab syntax by hand.
Open the editor

Basic sign table

LaTeX
\usepackage{tikz}
\usepackage{tkz-tab}

\begin{tikzpicture}
\tkzTabInit{$x$ / 1, $f'(x)$ / 1}
    {$-\infty$, $2$, $+\infty$}
\tkzTabLine{,+,z,-,}
\end{tikzpicture}

\tkzTabInit defines rows (name / height) and columns (x values). \tkzTabLine specifies signs: +, -, z (zero), t (single bar), d (double bar).

Variation table

LaTeX
\begin{tikzpicture}
\tkzTabInit{$x$ / 1, $f'(x)$ / 1, $f(x)$ / 1.5}
    {$-\infty$, $1$, $+\infty$}
\tkzTabLine{,-,z,+,}
\tkzTabVar{+/{$3$},-/{$-1$},+/{$+\infty$}}
\end{tikzpicture}

\tkzTabVar describes the variations: +/ (maximum), -/ (minimum). Arrow direction is determined automatically from the positions.

Double bars (asymptotes)

For forbidden values (poles, values outside the domain), double bars are used:

LaTeX
\begin{tikzpicture}
\tkzTabInit{$x$ / 1, $f'(x)$ / 1, $f(x)$ / 1.5}
    {$0$, $1$, $+\infty$}
\tkzTabLine{d,-,d,-,}
\tkzTabVar{D+/ /{$+\infty$},-D+/{$-\infty$}/{$+\infty$},-/{$0$}}
\end{tikzpicture}

The D notation indicates where to place the value relative to the double bar:

  • D-/ /{value}: at the left boundary — value to the right of the double bar (low)
  • -D/{value}/: at the right boundary — value to the left of the double bar (low)
  • -D+/{left}/{right}: interior — values on both sides
Visual editor
Create your tables visually with our table editor that automatically generates the correct tkz-tab code.

Complete example with sign and variation table

LaTeX
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usepackage{tkz-tab}

\begin{document}

% Variation table of f(x) = x·ln(x) on (0, +∞)
\begin{center}
\begin{tikzpicture}
\tkzTabInit[espcl=5]
    {$x$ / 1, $\ln(x) + 1$ / 1, $x \ln(x)$ / 2}
    {$0$, $\dfrac{1}{\mathrm{e}}$, $+\infty$}
\tkzTabLine{d,-,z,+,}
\tkzTabVar{D+/ /{$0$},-/{$-\dfrac{1}{\mathrm{e}}$},+/{$+\infty$}}
\end{tikzpicture}
\end{center}

\end{document}

Ready to create your tables?

Present your data professionally

Create a free account