Loading...
Loading...
LaTeX booktabs/tabularx/multirow/longtable packages for professional tables. Use when helping users create well-formatted tables, multi-page tables, or improve table appearance.
npx skill4agent add igbuend/grimbard booktabs\usepackage{booktabs} % professional horizontal rules
\usepackage{tabularx} % auto-width columns
\usepackage{multirow} % cells spanning rows
\usepackage{longtable} % multi-page tables
\usepackage{colortbl} % colored rows/cells (optional)
\usepackage{siunitx} % number alignment (optional)\begin{tabular}{|l|c|r|}
\hline
Name & Score & Grade \\ \hline
Alice & 95 & A \\ \hline
Bob & 82 & B \\ \hline
Carol & 78 & C \\ \hline
\end{tabular}\begin{tabular}{lcc}
\toprule
Name & Score & Grade \\
\midrule
Alice & 95 & A \\
Bob & 82 & B \\
Carol & 78 & C \\
\bottomrule
\end{tabular}\hline\toprule\midrule\bottomrule| Command | Use |
|---|---|
| Top of table (thicker) |
| Between header and body |
| Bottom of table (thicker) |
| Partial rule spanning columns 2–4 |
| Extra vertical space (group separator) |
| Custom extra space |
\cmidrule(l){1-2} % trim left
\cmidrule(r){3-4} % trim right
\cmidrule(lr){2-3} % trim both
\cmidrule{1-4} % no trim\begin{tabular}{llr}
\toprule
Category & Item & Price \\
\midrule
Fruit & Apple & 1.20 \\
& Banana & 0.80 \\
\addlinespace
Dairy & Milk & 2.50 \\
& Cheese & 4.00 \\
\bottomrule
\end{tabular}% X columns expand to fill \textwidth
\begin{tabularx}{\textwidth}{lXr}
\toprule
ID & Description & Price \\
\midrule
1 & A very long description that will wrap automatically & \$10 \\
2 & Short & \$20 \\
\bottomrule
\end{tabularx}| Column type | Behavior |
|---|---|
| Fixed (natural width) |
| Expands to fill remaining space (left-aligned) |
| Centered X column |
| Right-aligned X column |
| Paragraph, fixed width |
\usepackage{multirow}
\begin{tabular}{lcr}
\toprule
\multirow{2}{*}{Name} & \multicolumn{2}{c}{Scores} \\
\cmidrule(l){2-3}
& Math & English \\
\midrule
Alice & 95 & 88 \\
Bob & 72 & 91 \\
\bottomrule
\end{tabular}\multirow{nrows}{width}{content}*\multicolumn{ncols}{alignment}{content}\begin{tabular}{lcccccc}
\toprule
& \multicolumn{3}{c}{Treatment A} & \multicolumn{3}{c}{Treatment B} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7}
Subject & Pre & Post & $\Delta$ & Pre & Post & $\Delta$ \\
\midrule
1 & 5.2 & 3.1 & $-2.1$ & 4.8 & 4.5 & $-0.3$ \\
2 & 6.1 & 2.8 & $-3.3$ & 5.5 & 5.2 & $-0.3$ \\
\bottomrule
\end{tabular}\usepackage{longtable}
\begin{longtable}{lcc}
% Header for first page
\toprule
Name & Value & Unit \\
\midrule
\endfirsthead
% Header for continuation pages
\multicolumn{3}{l}{\textit{Continued from previous page}} \\
\toprule
Name & Value & Unit \\
\midrule
\endhead
% Footer for all pages except last
\midrule
\multicolumn{3}{r}{\textit{Continued on next page}} \\
\endfoot
% Footer for last page
\bottomrule
\endlastfoot
% Data rows
Alpha & 1.0 & m \\
Beta & 2.5 & kg \\
% ... many more rows ...
Omega & 9.9 & s \\
\caption{Long experimental data.}
\label{tab:longdata}
\end{longtable}longtabletabulartable\usepackage{colortbl}
\usepackage[table]{xcolor} % or load xcolor with table option
% Colored row
\rowcolor{blue!10}
Alice & 95 & A \\
% Colored cell
Alice & \cellcolor{green!20} 95 & A \\
% Alternating row colors (xcolor table option)
\rowcolors{2}{gray!10}{white} % start at row 2, alternate
\begin{tabular}{lcc}
\toprule
\rowcolor{white} % override for header
Name & Score & Grade \\
\midrule
Alice & 95 & A \\ % gray
Bob & 82 & B \\ % white
Carol & 78 & C \\ % gray
\bottomrule
\end{tabular}\usepackage{siunitx}
\begin{tabular}{l S[table-format=3.2] S[table-format=1.3]}
\toprule
{Material} & {Density} & {Error} \\
\midrule
Steel & 785.00 & 0.050 \\
Aluminum & 270.00 & 0.120 \\
Titanium & 450.00 & 0.008 \\
Gold & 1932.00 & 0.300 \\
\bottomrule
\end{tabular}{...}| S option | Example | Meaning |
|---|---|---|
| | 3 digits . 2 decimals |
| | sign, digits, exponent |
| | Round to decimal places |
| | Number of decimal places |
\begin{table}[htbp]
\centering
\caption{Performance comparison of algorithms.}
\label{tab:comparison}
\begin{tabular}{l S[table-format=2.1] S[table-format=3.0] c}
\toprule
{Method} & {Accuracy (\%)} & {Time (ms)} & {Converged?} \\
\midrule
Baseline & 72.3 & 150 & Yes \\
Improved & 85.1 & 230 & Yes \\
Proposed & 91.7 & 98 & Yes \\
\addlinespace
Oracle & 99.2 & 45 & N/A \\
\bottomrule
\end{tabular}
\end{table}| Problem | Cause | Fix |
|---|---|---|
| Vertical lines | Using ` | ` in column spec |
| Old habit | Use |
| Table too wide | Too many columns | Use |
| Incompatible | |
| Row height differences | Add |
| Text in S column | Wrap header in |
| Footnotes in table | | Use |
| Rules have gaps with color | Add |
\toprule\midrule\bottomrule\addlinespace\caption\small\footnotesizethreeparttable\arraystretch\renewcommand{\arraystretch}{1.2}