Skip to main content

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 OptionMeaningExample
widthWidth, can use relative valueswidth=0.8\textwidth (80% of type width)
heightHeightheight=5cm
scaleScale factorscale=0.5
angleRotation angleangle=90

It is recommended to omit the file extension: write sin instead of sin.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=\textwidth over scale—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}
Sine curve

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).

ParameterMeaningPriority Note
hhere, at the source positionOnly a suggestion; LaTeX will adjust if the page layout cannot accommodate
ttop, top of the current pageMost common choice in academic papers
bbottom, bottom of the current pageOften combined with t
pfloat page, independent float pageWhen there are many figures, they are automatically collected into an appendix page
! (e.g., [!h])Relax layout constraintsStack 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}
NameAgeScoreZhang San2092Li Si2188\begin{array}{|l|c|r|} \hline \text{Name} & \text{Age} & \text{Score} \\ \hline \text{Zhang San} & 20 & 92 \\ \text{Li Si} & 21 & 88 \\ \hline \end{array}
Column Format SymbolMeaning
l/c/rLeft / 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}
AlgorithmAccuracyRecallF1Model A0.910.880.89Model B0.930.900.91\begin{array}{lccc} \hline \text{Algorithm} & \text{Accuracy} & \text{Recall} & \text{F1} \\ \hline \text{Model A} & 0.91 & 0.88 & 0.89 \\ \text{Model B} & 0.93 & 0.90 & 0.91 \\ \hline \end{array}

💡 Journal and graduation thesis format guidelines almost always require three-line tables. Using | and \hline for fully bordered tables is fine for daily assignments, but please switch to booktabs before 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}

CommandSyntaxDescription
\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

DatasetTraining SetTest SetMNIST0.990.98CIFAR-100.950.91\begin{array}{lcc} \hline \text{Dataset} & \text{Training Set} & \text{Test Set} \\ \hline \text{MNIST} & 0.99 & 0.98 \\ \text{CIFAR-10} & 0.95 & 0.91 \\ \hline \end{array}

Two unwritten conventions: table captions go above the table, and figure captions go below the image; use the prefixes tab: and fig: 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 entire tabular in \resizebox{\textwidth}{!}{...} for proportional scaling; or use the tabularx package to automatically distribute column widths.

Summary

NeedCommand / Environment
Graphics\includegraphics[width=0.8\textwidth]{filename}
Figure/table floatsfigure / table + [htbp] + \centering + \caption + \label
Table skeletontabular, & for columns, \\ for rows
Three-line tablebooktabs: \toprule \midrule \bottomrule
Merge cells\multirow, \multicolumn
Partial horizontal line\cmidrule(lr){2-3}