
我已將其定義\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}
。但在其中一個部分中,我還想重新定義寬度/高度。我嘗試\renewcommand{\secimage}[heigth=4cm]{image}
像 renewcommand 的文檔定義選項一樣,但出現編譯錯誤。
如果有人可以請說出我做錯了什麼
答案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}