TeX - LaTeX Asked by Odysseus on April 19, 2021
I would like to build multiple slides of a frame in beamer by using a for-loop to load a specific image file out of a group in each slide.
Currently, I can either loop inside the frame and advance in slides:
documentclass{beamer}
usepackage{tikz}
begin{document}
begin{frame}
frametitle{A title}
framesubtitle{A subtitle}
foreach i in {1,2}{% loop
only<i>{includegraphics[height=0.3textheight]{pici.PNG}
This is pic i.}
}% end of loop
end{frame}
Or I can iteratively create different frames, leaving the same title but advancing the subtitle:
documentclass{beamer}
usepackage{tikz}
begin{document}
foreach i in {1,2}{% loop
begin{frame}
frametitle{A title}
framesubtitle{A subtitle for pic i}
includegraphics[height=0.3textheight]{pici.PNG}
end{frame}
}% end of loop
end{document}
The last outputs the result I am after, but it is only a workaround: frames are separate, but simply with redundant title.
When I try to loop inside the frame including only the subtitle, like below, it doesn’t work:
begin{frame}
foreach i in {1,2}{% loop
frametitle{A title}
framesubtitle{A subtitle for pic i{} that doesn't increment}
includegraphics[height=0.3textheight]{pici.PNG}
}% end of loop
end{frame}
Any ideas how one may achieve this? The advantage of this is that one can add a brief incrementing description in the subtitle, instead of the main text, without taking space thus from the textheight available for the image(s).
Edit:
Also tried defining an array and passing this as the argument, but still didn’t work:
documentclass{beamer}
usepackage{mwe} % added based on Andrew's comment
usepackage{tikz}
usepackage{arrayjobx}
%
begin{document}
newarraymyIncStr
readarray{myIncStr}{1&2}
begin{frame}
foreach iiChar in {1/a,2/b}{% loop
frametitle{A title}
framesubtitle<i>{Subtitle myIncStr(i)}
only<i>{%
includegraphics[height=0.3textheight]{example-image-iChar}
myIncStr(i)%
}
}% end of loop
end{frame}
end{document}
The only way I succeeded in the subtitle’s update was by using a counter in its argument. Note how its evaluation leads +1 the slide’s main text.
documentclass{beamer}
usepackage{mwe}
usepackage{tikz}
newcounter{acounter}
begin{document}
setcounter{acounter}{0}
begin{frame}
foreach iiChar in {1/a,2/b}{% loop
frametitle{A title}
framesubtitle<i>{Subtitle theacounter{}} % evaluated after stepping up
only<i>{%
includegraphics[height=0.3textheight]{example-image-iChar}
theacounter{}
stepcounter{acounter}
}
}% end of loop
end{frame}
end{document}
I don't know if this is good enough, but the framesubtitle
command accepts an <>
-argument to specify the slides. Unfortunately, it does not seem to be possible to define this inside a loop but you can set of the frame subtitles first and then load your images inside a loop:
documentclass{beamer}
usepackage{mwe}
usepackage{pgffor}
begin{document}
begin{frame}{A title}
framesubtitle<1>{A subtitle for pic 1 that doesn't increment}
framesubtitle<2>{A subtitle for pic 2 that doesn't increment}
foreach img in {a,b}{% loop
includegraphics<sli>[height=0.3textheight]{example-image-img}
}% end of loop
end{frame}
end{document}
This produces:
I am using images from the mwe package, which is why I am looping over a,b
instead of 1,2
. For reasons that I do not understand the following does not compile:
documentclass{beamer}
usepackage{mwe}
usepackage{pgffor}
begin{document}
begin{frame}{A title}
foreach ind/img in {1/a,2/b}{% loop
framesubtitle<ind>{A subtitle for pic ind{} that doesn't increment}
includegraphics<ind>[height=0.3textheight]{example-image-img}
}% end of loop
end{frame}
end{document}
Answered by user30471 on April 19, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP