最近写report 遇到一个问题,就是在图片或表格的交叉引用时, 便已没有问题,正文中相应位置显示 ?? 或者不显示, 查了相关资料之后发现问题出在\label{}和\caption{} 的前后顺序上。
问题如下:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
The price of several fruits are in Table \ref{table1}:
\begin{table}[ht]
\centering
\begin{tabular}{cc}
\toprule
types & Price \\
\midrule
Apple & 10\\
Banana & 9\\
Pear & 12 \\
\bottomrule
\end{tabular}
\label{table1}
\caption{The price table.}
\end{table}
\end{document}
相应的PDF文件如下: 没有显示 Table 后并没有出现1, 编译没有错误:

正确的顺序应该是:\label{}应该在\caption{}的后边,如下所示。
\documentclass{article}
\usepackage{booktabs}
\begin{document}
The price of several fruits are in Table \ref{table1}:
\begin{table}[ht]
\centering
\begin{tabular}{cc}
\toprule
types & Price \\
\midrule
Apple & 10\\
Banana & 9\\
Pear & 12 \\
\bottomrule
\end{tabular}
\caption{The price table.}
\label{table1}
\end{table}
\end{document}
生成的pdf 文件如下:

1934

被折叠的 条评论
为什么被折叠?



