charts-plugins
Figures and Tables
Figures and tables are the skeleton of a paper. This chapter covers four things: figure commands and floats, basic tables, academic three-line tables, and merging cells.
LaTeX's management philosophy for figures and tables is consistent with numbering: you only provide content and captions; position, numbering, and references are all automatic.
Graphics: The graphicx Package
Inserting graphics requires only two commands: load graphicx in the preamble, and use \includegraphics in the body to place the image file.
| Common Option | Meaning | Example |
|---|---|---|
| width | Width, can use relative values | width=0.8\textwidth (80% of type width) |
| height | Height | height=5cm |
| scale | Scale factor | scale=0.5 |
| angle | Rotation angle | angle=90 |
It is recommended to omit the file extension: write
sininstead ofsin.png. LaTeX will automatically search for formats supported by the current compiler (XeLaTeX supports PDF, PNG, JPG, etc.); changing format does not require modifying the source.
💡 When controlling image size, prefer the proportional value
width=\textwidthoverscale—the former ensures the image never exceeds the type area, while the latter may unexpectedly overflow under different font size settings.
Floats: The figure Environment
Images should not be placed directly in the text flow; the standard practice is to put them in the figure float environment.
Example: Standard Figure
\documentclass{ctexart}
\usepackage{graphicx} % Essential package for graphics
\begin{document}
The graph of the sine function $y = \sin x$ is shown in Figure~\ref{fig:sin}.
\begin{figure}[htbp] % Float environment; position parameters see table below
\centering % Image centered inside the float
\includegraphics[width=0.6\textwidth]{sin}
\caption{Sine curve} % Caption; number generated automatically
\label{fig:sin} % Label for \ref reference
\end{figure}
\end{document}

Figure 1: Sine curve
"Why did my image end up somewhere else?"—this is not a bug; it is the float mechanism at work: LaTeX chooses a position for each figure that does not create large gaps. When you really need to pin it down, use the float package's
[H]parameter (uppercase, meaning here and do not move).
| Parameter | Meaning | Priority Note |
|---|---|---|
| h | here, at the source position | Only a suggestion; LaTeX will adjust if the page layout cannot accommodate |
| t | top, top of the current page | Most common choice in academic papers |
| b | bottom, bottom of the current page | Often combined with t |
| p | float page, independent float page | When there are many figures, they are automatically collected into an appendix page |
| ! (e.g., [!h]) | Relax layout constraints | Stack with strong requests |
Basic Tables: The tabular Environment
The syntactic skeleton of a table is the same as a matrix: & separates columns, \\ starts a new line, and column formats are declared in the environment argument.
Example: Fully Bordered Table
\documentclass{ctexart}
\begin{document}
\begin{tabular}{|l|c|r|} % Column format: left/center/right alignment, vertical lines separate
\hline % Top horizontal line
Name & Age & Score \\ % & separates columns, \\ starts a new line
\hline
Zhang San & 20 & 92 \\
Li Si & 21 & 88 \\
\hline % Bottom horizontal line
\end{tabular}
\end{document}
| Column Format Symbol | Meaning |
|---|---|
| l/c/r | Left / center / right alignment for the column |
| | | Draw a vertical line at this position |
| p{2cm} | Fixed column width, with automatic line breaks inside cells |
Academic Standard: booktabs Three-line Tables
Open any formal publication, and tables are "three horizontal lines, zero vertical lines"—this is called a three-line table, provided by the booktabs package.
Example: Three-line Table
\documentclass{ctexart}
\usepackage{booktabs} % Three-line table package
\begin{document}
\begin{tabular}{lccc} % Three-line tables use no vertical lines
\toprule % Top rule, thickest
Algorithm & Accuracy & Recall & F1 \\
\midrule % Middle rule, thinner
Model A & 0.91 & 0.88 & 0.89 \\
Model B & 0.93 & 0.90 & 0.91 \\
\bottomrule % Bottom rule, thickest
\end{tabular}
\end{document}
💡 Journal and graduation thesis format guidelines almost always require three-line tables. Using
|and\hlinefor fully bordered tables is fine for daily assignments, but please switch tobooktabsbefore submission.
Merging Cells: multirow and multicolumn
Complex table headers need merging: horizontal merging uses \multicolumn (built into LaTeX), and vertical merging uses \multirow (requires loading the multirow package).
Example: Double-row Header
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow} % Merge cells vertically
\begin{document}
\begin{tabular}{lcc}
\toprule
\multirow{2}{*}{Dataset} & \multicolumn{2}{c}{Accuracy} \\
\cmidrule(lr){2-3} % Partial horizontal line for columns 2~3
& Training Set & Test Set \\
\midrule
MNIST & 0.99 & 0.98 \\
CIFAR-10 & 0.95 & 0.91 \\
\bottomrule
\end{tabular}
\end{document}

| Command | Syntax | Description |
|---|---|---|
\multirow | \multirow{rows}{width}{content} | Span rows vertically; leave the corresponding positions empty in the spanned rows |
\multicolumn | \multicolumn{columns}{col-format}{content} | Span columns horizontally; the cell's column format must be rewritten |
\cmidrule | \cmidrule(lr){2-3} | Partial horizontal line; (lr) means a little space at both ends, more refined |
Table Captions and Overall Floating
Tables also live in floats; the environment is table, and the rest of the routine is exactly the same as figure.
Example: Numbered Table
\begin{table}[htbp]
\centering
\caption{Experimental Result Comparison} % Caption (conventionally above the table)
\label{tab:result}
\begin{tabular}{lcc}
\toprule
Dataset & Training set & Test set \\
\midrule
MNIST & 0.99 & 0.98 \\
CIFAR-10 & 0.95 & 0.91 \\
\bottomrule
\end{tabular}
\end{table}
Table 1: Experimental Result Comparison
Two unwritten conventions: table captions go above the table, and figure captions go below the image; use the prefixes
tab:andfig:for labels, so the type is immediately recognizable when referenced. When a table is wider than the type area, two emergency solutions exist: wrap the entiretabularin\resizebox{\textwidth}{!}{...}for proportional scaling; or use thetabularxpackage to automatically distribute column widths.
Summary
| Need | Command / Environment |
|---|---|
| Graphics | \includegraphics[width=0.8\textwidth]{filename} |
| Figure/table floats | figure / table + [htbp] + \centering + \caption + \label |
| Table skeleton | tabular, & for columns, \\ for rows |
| Three-line table | booktabs: \toprule \midrule \bottomrule |
| Merge cells | \multirow, \multicolumn |
| Partial horizontal line | \cmidrule(lr){2-3} |