[Tex/LaTex] How to make chapter page in Beamer

beamer

I am finding some solution in website.

Before beginning document, type the following:

\AtBeginSection[]{
    \begin{frame}
    \vfill
    \centering
    \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
        \usebeamerfont{title}\insertsectionhead\par%
    \end{beamercolorbox}
    \vfill
    \end{frame}
}

And when I need some chapter page, I can put it by typing

\section{text}

However, the following code is failed:

\section{\textit{Chap. 1} \color{black}{text}}

Can someone let me know how to resolve?

Best Answer

We need to make the commands \textit{} and \color{}{} to robust commands. The following example will help you:

\documentclass{beamer}

\usepackage{etoolbox,lipsum}

\robustify{\textit}
\robustify{\color}

\AtBeginSection[]{
    \begin{frame}
    \vfill
    \centering
    \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
        \usebeamerfont{title}\insertsectionhead\par%
    \end{beamercolorbox}
    \vfill
    \end{frame}
}

\begin{document}

\section{text}
Test first section.
\clearpage

\section{\textit{Chap. 1} \color{black}{text}}
Test second section with color changed.

\end{document}

I have used the \robustify{} command of the etoolbox package for fixing the problem.