
\secimage
私はセクションのタイトルページでイメージとして定義しました:
\AtBeginSection[]{
\begin{frame}
\vfill
\begin{center}
%\centering
\includegraphics[width=4cm]{\secimage}\\
\begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
\usebeamerfont{title}\insertsectionhead\par%
\end{beamercolorbox}
\end{center}
\vfill
\end{frame}
}
そして、各セクションで、 を使用してイメージを再定義します\renewcommand{\secimage}{figureofchoice}
。ただし、セクションの 1 つで、幅/高さも再定義したいと思います。renewcommand\renewcommand{\secimage}[heigth=4cm]{image}
のドキュメントでオプションが定義されているように試しましたが、コンパイル エラーが発生します。
誰か私が何を間違っているのか教えてください
答え1
次のコードは表記法の変更を提案しています。 の代わりに\renewcommand{\secimage}{<image>}
を使用し、\setsecimage{[<options>]{<image>}}
追加オプションを指定できます。
\newcommand{\setsecimage}[1]{\gdef\secimagedetail{#1}}% Store section image detail
\let\secimagedetail\relax% Default definition of section image detail
\AtBeginSection{
\begin{frame}
\vfill
\begin{center}
\ifx\secimagedetail\relax\else % If section image exists
\expandafter\includegraphics\secimagedetail \\
\fi
\begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
\usebeamerfont{title}\insertsectionhead\par%
\end{beamercolorbox}
\end{center}
\vfill
\end{frame}
\let\secimagedetail\relax% Remove section image detail
}
典型的な使用法は
\setsecimage{[width=50pt]{example-image}}
\section{A section}
\section{Another section}
\setsecimage{{example-image}}
\section{Final section}
\setsecimage
に が含まれていない場合(上記コードの最後のセクションの場合) でも、のように引数を<options>
「二重括弧」で囲む必要があります。<image>
\setsecimage{{<image>}}
答え2
\setsecimage
と同じ構文でコマンドを定義します\includegraphics
。秘訣は、別のマクロを再定義することです。
\documentclass{beamer}
\AtBeginSection[]{
\begin{frame}
\vfill
\begin{center}
%\centering
\addsecimage\\
\begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
\usebeamerfont{title}\insertsectionhead\par%
\end{beamercolorbox}
\end{center}
\vfill
\end{frame}
}
\newcommand{\setsecimage}[2][width=4cm]{%
\renewcommand{\addsecimage}{\includegraphics[#1]{#2}}%
}
\newcommand{\addsecimage}{} % initialize
\begin{document}
\setsecimage{example-image}
\section{Normal}
\setsecimage[width=2cm]{example-image-a}
\section{Small}
\end{document}