Latex - 使用循環並排數字

Latex - 使用循環並排數字

我試著將 6 個數字分成 3 行 2 列:

\foreach \x in {1,2,3,4,5,6,7,8,9,10,11,12}
{
\begin{figure}[h]
\caption{This is the caption.}
\vspace{0.0cm} \centering
\includegraphics[height = 5.4cm]{figures/fig\x.eps}
\end{figure}
}

我只想在第一個圖頁中有一個標題,並在下一頁中為接下來的 6 個圖提供相同的圖號。

答案1

我使用了pgffor(或tikz) 套件、一對循環(內部和外部)和幾個條件來完善結果。在實際專案中,我將使用該subfigure套件和兩個獨立頁面來獲得兩個部分的可點擊交叉引用。

我附上一個範例和頁面預覽。這 12 張圖片 ( fig*) 必須儲存在figures/資料夾中才能成功編譯程式碼。

%! *latex morepics.tex
\documentclass[a4paper]{article}
\usepackage{pgffor}% or tikz
\usepackage{mwe}
%\usepackage{subfigure}

\begin{document}
\foreach \x in {1,2} {%
\ifnum\x=2\addtocounter{figure}{-1}\fi
\newpage
\begin{figure}%[!ht]
\centering
\caption{This is the caption.}%
\foreach \y in {1,...,6}{%
  \pgfmathparse{int((\x-1)*6+\y)}
  % We need figures/fig1 to figures/fig12 to be able to compile this particular example.
  \includegraphics[height=6.5cm]{figures/fig\pgfmathresult} 
  \ifnum\y=2\par\fi
  \ifnum\y=4\par\fi
  }% End of the inner \foreach...
\end{figure}%
}% End of the outer \foreach...
\end{document}

姆韋

編輯:包中的變更: + mwe、 - subfigure、 - tikz、 + pgffor。現在不再使用圖 1-6 並使用它們兩次,而是載入圖 1 至 12。

相關內容