3

I want to put a tcolorbox in one frame of beamer class. I create the vd enviroment such below code.

Compiling the following code meets error "File ended while scanning use of \beamer@collect@@body." Please explain why it is and how to correct the code.

Thank you in advance!

\documentclass[17pt, hyperref={unicode},aspectratio=169]{beamer}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[most,many]{tcolorbox}
\newenvironment{vd}{\begin{frame}\begin{tcolorbox}}
{\end{tcolorbox}\end{frame}}
\begin{document}
\begin{frame}
\begin{tcolorbox}
    Contents of enviroment.
\end{tcolorbox}
\end{frame}

\begin{vd}
    Contents of enviroment.
\end{vd}
\end{document}

1 Answer 1

6

I think this has to do with the very sensitive way in which beamer frame environments collect their contents. The issue is described on page 61 of the Beamer User's Guide (v3.66; end of section 8.1).

Basically, when defining other environments using frames, it doesn't work well to have another \end{...} command in the closing block.

The Beamer User's Guide suggests getting around this by defining further commands that begin and start the inner environment, like this:

\documentclass[17pt, hyperref={unicode},aspectratio=169]{beamer}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[most,many]{tcolorbox}
\newenvironment{vd}{\begin{frame}\tcolorboxstart}
{\tcolorboxend\end{frame}}

\newcommand{\tcolorboxstart}{\begin{tcolorbox}}
\newcommand{\tcolorboxend}{\end{tcolorbox}}

\begin{document}
\begin{frame}
\begin{tcolorbox}
    Contents of environment.
\end{tcolorbox}
\end{frame}

\begin{vd}
    Contents of environment.
\end{vd}
\end{document}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.