我是 Latex 中 for 循环的新手,不确定以下方法是否可行。这基本上就是我想要实现的:
\documentclass{article}
\begin{document}
\foreach \x in {a,b,c}
{
\includegraphics[scale=.8]{fig\x.pdf}
\caption{So, three figures displayed, and this one has the number \x of the letter position (or iteration count)} % ie. 1 for a, 2 for b, 3 for c
\clearpage
}
\end{document}
那么,是否可以根据上面的代码仅显示(例如保存在变量中?)迭代步骤?
任何帮助深表感谢,
编辑1:
这有效:
\foreach \x in {{s01.2015.04.09_2015.04.16}, {s02.2015.04.17_2015.04.24}, {s03.2015.04.25_2015.04.30}, {s04.2015.05.01_2015.05.08}, {s05.2015.05.09_2015.05.16}, {s06.2015.05.17_2015.05.24}, {s07.2015.05.25_2015.05.31}, {s08.2015.06.01_2015.06.08}, {s09.2015.06.09_2015.06.16}, {s10.2015.06.17_2015.06.24}, {s11.2015.06.25_2015.06.30}, {s12.2015.07.01_2015.07.08}, {s13.2015.07.09_2015.07.16}, {s14.2015.07.17_2015.07.24}, {s15.2015.07.25_2015.07.31}}
{
\begin{figure}[p]
\centering
\includegraphics[scale=.7,angle=-90]{../figuras/anexo2/chl.\x.aqua-color.pdf}
\caption{Distribución espacial de la flota pesquera industrial sobre la concentración de clorofila-a superficial del mar en el Mar Peruano durante la semana de la primera temporada de pesca 2015.}
\end{figure}
\clearpage
}
下面这个抛出了这个错误信息Undefined control sequence \foreach \x[count=\y] Undefined control sequence }
::
\foreach \x[count=\y] in {{s01.2015.04.09_2015.04.16}, {s02.2015.04.17_2015.04.24}, {s03.2015.04.25_2015.04.30}, {s04.2015.05.01_2015.05.08}, {s05.2015.05.09_2015.05.16}, {s06.2015.05.17_2015.05.24}, {s07.2015.05.25_2015.05.31}, {s08.2015.06.01_2015.06.08}, {s09.2015.06.09_2015.06.16}, {s10.2015.06.17_2015.06.24}, {s11.2015.06.25_2015.06.30}, {s12.2015.07.01_2015.07.08}, {s13.2015.07.09_2015.07.16}, {s14.2015.07.17_2015.07.24}, {s15.2015.07.25_2015.07.31}}
{
\begin{figure}[p]
\centering
\includegraphics[scale=.7,angle=-90]{../figuras/anexo1/sst.\x.aqua-color.pdf}
\caption{Distribución espacial de la flota pesquera industrial sobre la temperatura superficial del mar en el Mar Peruano durante la semana \y de la primera temporada de pesca 2015.}
\end{figure}
\clearpage
}
答案1
像这样?
\documentclass{article}
\usepackage{pgffor}
\usepackage{graphicx}
\begin{document}
\foreach \x in {a,b,c}
{
\begin{figure}[p]
\includegraphics[scale=.5]{example-image-\x}
\caption{So, three figures displayed, and this one has the number \x\ of the letter position (or iteration count)} % ie. 1 for a, 2 for b, 3 for c
\end{figure}
\clearpage
}
\end{document}
或者简单地说,
\documentclass{article}
\usepackage{pgffor}
\begin{document}
\foreach \x in {1,...,10}
{
This is step \x, \par
}
\end{document}
这是为了解决评论问题。
\documentclass{article}
\usepackage{pgffor}
\begin{document}
\foreach \x in {{s01.2015.37.09\_2015.09.24},{s01.2015.37.09\_2015.09.25},{s01.2015.37.09\_2015.09.23}}
{
This is step \x, \par
}
\end{document}
顺便说一句,这里需要小心处理下划线。
\documentclass{article}
\usepackage{pgffor}
\begin{document}
\foreach \x[count=\y] in {{s01.2015.37.09_2015.09.24},{s01.2015.37.09_2015.09.25},{s01.2015.37.09_2015.09.23}}
{
This is step \y, \par
}
\end{document}
以下方法同样有效:
\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage[demo]{graphicx}
\usepackage{pgffor}
\begin{document}
\foreach \x[count=\y] in {{s01.2015.04.09_2015.04.16}, {s02.2015.04.17_2015.04.24}, {s03.2015.04.25_2015.04.30}, {s04.2015.05.01_2015.05.08}, {s05.2015.05.09_2015.05.16}, {s06.2015.05.17_2015.05.24}, {s07.2015.05.25_2015.05.31}, {s08.2015.06.01_2015.06.08}, {s09.2015.06.09_2015.06.16}, {s10.2015.06.17_2015.06.24}, {s11.2015.06.25_2015.06.30}, {s12.2015.07.01_2015.07.08}, {s13.2015.07.09_2015.07.16}, {s14.2015.07.17_2015.07.24}, {s15.2015.07.25_2015.07.31}}
{
\begin{figure}[p]
\centering
\includegraphics[scale=.7,angle=-90]{../figuras/anexo1/sst.\x.aqua-color.pdf}
\caption{Distribución espacial de la flota pesquera industrial sobre la temperatura superficial del mar en el Mar Peruano durante la semana {\LARGE\bfseries \y} de la primera temporada de pesca 2015.}
\end{figure}
\clearpage
}
\end{document}