Переопределение высоты изображения с помощью renewcommand

Переопределение высоты изображения с помощью renewcommand

Я определил \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}

введите описание изображения здесь

Связанный контент