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;
    }
3
  • 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
    Commented May 12, 2017 at 13:11
  • Btw listing already have a caption option build in.
    – daleif
    Commented May 12, 2017 at 13:12
  • Is the built-in option compatible with babel?
    – katang
    Commented May 12, 2017 at 20:29

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .