\foreach \n in {5,-30,65,75}{
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{images/plots_for_theta_0_at\n.eps}
\caption{PD controller response at $\theta_0 = \n^\circ$}
\label{fig: response at \n}
\end{figure}
}
我这样做了,但是当我引用 5 处的响应时它不起作用。有没有解决方法,因为我实际上需要连续添加 8 个这样的数字?
答案1
我尝试使用您的代码片段编写 MWE。此 MWE 运行良好,因此不清楚您的文档与我的 MWE 有何不同:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage[skip=1ex]{caption}
\usepackage{pgffor}
\begin{document}
\foreach \n in {5,-30,65,75}{
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{images/plots_for_theta_0_at\n.eps}
\caption{PD controller response at $\theta_0 = \n^\circ$}
\label{fig: response at \n}
\end{figure}
}
See figured \ref{fig: response at 5}, \ref{fig: response at -30}, \ref{fig: response at 65} and \ref{fig: response at 75}
\end{document}