1

I am attempting to use package caption with beamer. The MWE below runs fine. If I uncomment captionof, I am presented with message you cannot use '\unskip' in vertical mode. To be even more enigmatic, if I change to document class memoir, even with captionof compiles fine. What is going on here?

   \documentclass{beamer}
    %\documentclass{memoir}

    \usepackage{listingsutf8}   % Use program listings
    \usepackage{caption}

    \makeatletter
    \newcommand\SourceFileBad[4][]{
        \lstinputlisting{#2}
    %   \captionof{lstlisting}{#3}%
    }
    \makeatother

    \begin{document}
    \SourceFileBad {sumvec.c}{The file}{lst:sumvec.c}
    \end{document}

    % % % % % % % % % % % % % % % % % The sumvec file, for completeness
    int sumvec(int v[N])
    {
        int i, sum = 0;
        for (i = 0; i < N; i++) longer line to test
          sum += v[i];
        return sum;
    }
  • Beamer is is very own thing so you really should not expect it to work with packages that change core stuff. Why do you want to use the caption package with beamer in the first place? – daleif May 12 '17 at 13:11
  • Btw listing already have a caption option build in. – daleif May 12 '17 at 13:12
  • Is the built-in option compatible with babel? – katang May 12 '17 at 20:29
3

I don't see any conflict, you just have to use a frame environment:

\begin{frame}
\SourceFileBad{sumvec.c}{The file}{lst:sumvec.c}
\end{frame}

Full MWE:

\begin{filecontents}{sumvec.c}
int sumvec(int v[N])
{
    int i, sum = 0;
    for (i = 0; i < N; i++) longer line to test
      sum += v[i];
    return sum;
}
\end{filecontents}

\documentclass{beamer}

\usepackage{listingsutf8}   
\usepackage{caption}

\newcommand\SourceFileBad[4][]{
    \lstinputlisting{#2}
   \captionof{lstlisting}{#3}%
}

\begin{document}
\begin{frame}
\SourceFileBad{sumvec.c}{The file}{lst:sumvec.c}
\end{frame}
\end{document}

enter image description here

|improve this answer|||||

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.