
我想在 Beamer 中包含一系列圖像(儘管它可以在其他類型的文檔中)。類似選項的東西相片集在 LibreOffice 和 MS PowerPoint 中。
我所做的是製作一個模板(我可以修改):
%s
\begin{frame}
\frametitle{%s}
\framesubtitle{%s}
\centering
\includegraphics[width=0.9\textwidth]{%s}
\end{frame}
然後我使用 Python 腳本產生每個幀的程式碼,如下所示:
tex_file = open(filename + '.tex', 'a+')
for name in list_files:
print >> tex_file, s1 %(comment, title, subtitle, name)
tex_file.close()
之後,我只需\include
在主文件中使用 an 來添加圖像序列。
我的問題:有這個任務的包嗎?或者更好的方法來做到這一點?
答案1
這是一個使用的選項multido
:
\documentclass{beamer}
\usepackage{multido}
\begin{document}
\multido{\i=1+1}{9}{%
\begin{frame}
\frametitle{Title: \i}
\framesubtitle{Subtitle: \i}
\centering
\includegraphics[width=.9\linewidth]{example-image-\i}
\end{frame}
}
\end{document}
語法\multido{<var>=<start>+<inc>}{<times}{<stuff>}
定義<var>
為<start>
,以<inc>
總次數遞增<times>-1
(因為第一個值算是一次迭代),並且每次迭代都會執行<stuff>
。特殊的\i
- 表示法意味著這<var>
將是一個i
整數。
上面的範例假設從一個元素到下一個元素的變更最小。例如,如果您對每張照片的框架標題、副標題和任何附加評論有不同的內容,那麼使用類似清單的方法會更好。對於比,中提到的任何技術如何迭代逗號分隔的清單?會有幫助的。
答案2
我有一個 tex 文件,我編寫它來生成照片顯示,可以執行類似的操作。對我來說,目標是在覆蓋頁面的網格上排列不斷變化的照片集。我用來tikz
循環遍歷照片(儲存為逗號分隔的圖像檔案名稱清單)並放置照片。
當您談論透過 python 產生檔案名稱列表時,您可以輕鬆填充變數列表,如下所示。
這是一個精簡版本:
\documentclass{article}
\usepackage{mwe}
\usepackage{graphicx}
\usepackage{tikz}
\def\MyImages{example-image-a,example-image-b,example-image-c}% list of images
\begin{document}
\newdimen\X
\begin{tikzpicture}[overlay,
picture/.style={draw,rectangle,anchor=#1,inner sep=0pt,outer sep=0pt}
]
\X=0mm
\foreach \Image in \MyImages {
\node[picture=north west] at (\X,-101.5mm)
{\includegraphics[width=49.5mm,height=35mm]{\Image}};
\global\advance\X by 49.5mm
}
\end{tikzpicture}
\end{document}
這會產生: