Latex 交叉引用图片时编译没有问题,pdf 文件中却显示?? 或者不显示 ------ 解决方案

最近写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, 编译没有错误:
Latex 交叉引用图片时编译没有问题,pdf 文件中却显示?? 或者不显示 ------ 解决方案_第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 文件如下:
Latex 交叉引用图片时编译没有问题,pdf 文件中却显示?? 或者不显示 ------ 解决方案_第2张图片

你可能感兴趣的:(Latex)