Overleaf中subfigure子图\ref引用失效问题的排查与解决咨询
Overleaf中subfigure子图\ref引用失效问题的排查与解决咨询
嗨,我看了你贴的代码,发现几个可能导致子图引用失效的问题,咱们一个个来解决:
- 包名拼写错误:你写的
\usepackage{graphix}是错的,正确的图片处理包应该是\usepackage{graphicx}(多了一个字母c),这个错误会导致图片加载异常,甚至干扰整个figure环境的编译流程,自然就会让引用失效。 - 多余的反引号干扰编译:你的代码里有好几处不该出现的反引号(
),比如第一个子图的\includegraphics结尾、\caption{MPC}后面、\label{subfig:mpc}`后面,这些反引号属于无效的LaTeX语法,会打乱编译时对label的记录,直接导致引用无法被正确解析。 - 编译次数不足:LaTeX的交叉引用机制需要至少两次编译才能生效——第一次编译生成记录引用信息的
.aux文件,第二次编译才能把\ref替换成正确的编号。Overleaf通常会自动处理,但如果遇到问题,可以手动点击顶部的「Recompile」按钮多编译几次。
另外,第一个子图里\caption后面加的\\换行其实没必要,不过这个不是影响引用的核心问题,修正上面几个点就够了。
给你整理好的修正后代码:
\usepackage{subcaption} \usepackage{graphicx} % 修正包名拼写 \begin{document} The numerical results are shown in \ref{smpc_and_mpc}. \begin{figure}[ht] \centering \begin{subfigure}{\textwidth} \centering \includegraphics[width=0.95\textwidth]{Gambar/mpc_FPA.eps} % 移除多余反引号 \caption{MPC} % 移除多余反引号 \label{subfig:mpc} % 移除多余反引号 \end{subfigure} \begin{subfigure}{\textwidth} \centering \includegraphics[width=0.95\textwidth]{Gambar/SMPC.eps} \caption{SMPC} \label{subfig:smpc} \end{subfigure} \caption{Flight path angle responses tested using 200 different parameters with 20\% deviation about nominal values of $a_{13}$ and $a_{23}$} \label{smpc_and_mpc} \end{figure} \ref{subfig:mpc} and \ref{subfig:smpc} compare the flight path angle responses of MPC and SMPC, using parameters from \ref{tabel_SMPC}. \end{document}
按照上面的修改重新编译两次,应该就能得到你想要的Figure 1(a)这类正确的引用格式啦。
备注:内容来源于stack exchange,提问作者Heri
相关产品推荐
相关产品推荐

