2

I try to provide a specialized frame in beamer using columns. The code is below:

\documentclass[mathserif]{beamer}

\newenvironment{questionframe}[1]{
    \begin{frame}{#1}\begin{columns}[t]
}{
    \end{columns}\end{frame}
}

\newenvironment{question}
    {\begin{column}{0.5\textwidth}}
    {\end{column}}
\newenvironment{answer}
    {\begin{column}{0.5\textwidth}}
    {\end{column}}

\begin{document}

\begin{questionframe}{Question frame, very long, very long}
    \begin{question}
        This is a question!
    \end{question}
    \begin{answer}
        This is the answer!
    \end{answer}
\end{questionframe}

\end{document}

I get the following error:

! File ended while scanning use of \beamer@collect@@body.

Yet, if I move the "columns" environment out of questionframe environment definitionstraight forward to the question in the document, the compilation is ok...

Could someone explain me the problem? Anyway to prevent this?

Any hint will be welcome.

3
  • Try \newenvironment{questionframe}[1]{ \begin{frame}{#1}\columns[t] }{\endcolumns \end{frame} }
    – user31729
    Dec 26 '18 at 16:59
  • Wonderful. It is working very well (in my simple and in my complex example). I was not aware of the commands \columns and \endcolumns. Dec 26 '18 at 17:17
  • \newenvironment{foo} actually defines \foo and \endfoo...
    – user31729
    Dec 26 '18 at 17:27
3

Hiding the frame environment in another environment can cause all kinds of problems, especially if you need to put fragile content in your frame, for example listings or some tikz pictures.

If you really must do it, beamer had a special frame option environment in which you can tell it the name of the new environment. (For more information about this see the beamer user guide, page 62)

Some other comments:

  • the mathserif option is obsolete, a warning in your log file tell you that you should use \usefonttheme[onlymath]{serif} instead

  • You cannot fit two columns of .5\textwidth besides each other, that leaved no room for the intra-column space. Either make them a bit smaller or use the onlytextwidth option


\documentclass{beamer}

\usefonttheme[onlymath]{serif}

\newenvironment{questionframe}[1]
       {\begin{frame}[environment=questionframe]\frametitle{#1}\begin{columns}[t,onlytextwidth]}
       {\end{columns}\end{frame}}

\newenvironment{question}
    {\begin{column}{0.48\textwidth}}
    {\end{column}}
\newenvironment{answer}
    {\begin{column}{0.48\textwidth}}
    {\end{column}}

\begin{document}

\begin{questionframe}{Question frame, very long, very long}
    \begin{question}
        This is a question!
    \end{question}
    \begin{answer}
        This is the answer!
    \end{answer}
\end{questionframe}

\end{document}

enter image description here

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.