Redefinindo a altura da imagem com restartcommand

Redefinindo a altura da imagem com restartcommand

Eu defini \secimagecomo imagem na página de título da minha seção:

\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}
}

E para cada seção eu redefino a imagem usando \renewcommand{\secimage}{figureofchoice}. Mas em uma das seções eu gostaria também de redefinir a largura/altura. Tentei \renewcommand{\secimage}[heigth=4cm]{image}como se a documentação do restartcommand definisse as opções, mas ocorreu um erro de compilação.

Se alguém pudesse dizer o que estou fazendo de errado

Responder1

O código a seguir sugere uma mudança na sua notação. Em vez de \renewcommand{\secimage}{<image>}, você usa \setsecimage{[<options>]{<image>}}onde permite especificar opções adicionais.

\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
}

com um uso típico semelhante

\setsecimage{[width=50pt]{example-image}}

\section{A section}

\section{Another section}

\setsecimage{{example-image}}

\section{Final section}

Se você \setsecimagenão incluir nenhum <options>(para a seção final do código acima), você ainda terá que "colchetes duplos" no <image>argumento, como em \setsecimage{{<image>}}.

Responder2

Defina um \setsecimagecomando com a mesma sintaxe de \includegraphics. O truque é que ele redefine outra macro.

\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}

insira a descrição da imagem aqui

informação relacionada