0

OK. I'm truly at my wits' end.

I asked my prof. for his slides because I thought they looked really nice. He sent me the tex file and it works fine so far, however, I simply want to include a figure in there with a caption. \includegraphics{ ... ] seems to work fine but when I try to wrap it around a begin/end{figure} environment it gets ignored.

\documentclass[a4paper,landscape]{slides}
\usepackage[centertags,reqno]{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{rotating}

\topmargin -2cm \textheight 17cm \textwidth 24cm
\special{landscape}     %landscape

\newcommand{\nextslide}[1]{\end{slide}\begin{slide}{\bf \underline{\centerline{#1}}}}

\begin{document}

\begin{slide}

\nextslide{Fun Stuff}

% Doesn't work 
%\begin{figure}[h]
%\centering
%\includegraphics{foo}
%\caption{caption}
%\end{figure}

% Does work 
\includegraphics{foo}

\end{slide}

\end{document}
  • 2
    A \begin{figure} starts a float, which is not really useful on slides - content is supposed to be fixed, not floating. If you want captions and references you could try the \captionof command from the caption package. – Marijn Feb 19 '18 at 9:38
  • This question should not have the beamer tag, imho. – Johannes_B Feb 19 '18 at 9:46
  • @Johannes_B Already changed that :) – user36296 Feb 19 '18 at 9:47
  • just use \includegraphics{foo} – David Carlisle Feb 19 '18 at 10:05
  • 1
    I've posted an example. However, I agree with @DavidCarlisle that the slides class is not the best choice for presentations (the best choice would be beamer for almost all purposes). – Marijn Feb 19 '18 at 11:34
2

For using captions without a float you can use the caption package (see Label and caption without float). To extend on that answer, an important remark is given in the caption documentation (currently page 18):

[...] you should use both \captionof and \captionof* only inside boxes or environments [...]

Therefore, you should either use an existing environment (such as \begin{center} \end{center}) or a custom environment (defined with \newenvironment) to indicate the scope of the caption (m.m. for boxes).

To use \captionof, a type must be declared with \DeclareCaptionType, which is unfortunately missing from the package documentation (note that the current version on CTAN is dated 2016-05-22 while the documentation is dated 2011-11-02). The identifier for the type must be chosen not to conflict with existing commands (e.g., in the MWE below the identifier figure generates an error while myfigure is ok).

Code:

\documentclass[a4paper,landscape]{slides}
\usepackage[centertags,reqno]{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{rotating}

\usepackage{caption}
\DeclareCaptionType{myfigure}[Figure]
\newenvironment{nonfloat}{}{}

\topmargin -2cm \textheight 17cm \textwidth 24cm
\special{landscape}     %landscape

\newcommand{\nextslide}[1]{\end{slide}\begin{slide}{\bf \underline{\centerline{#1}}}}

\begin{document}

\begin{slide}
\nextslide{Fun Stuff}
\begin{nonfloat}
\includegraphics{example-image}
\captionof{myfigure}{This is a figure.}
\end{nonfloat}

\end{slide}

\begin{slide}
\nextslide{Centered}
\begin{center}
\includegraphics{example-image-b}
\captionof{myfigure}{This is a centered figure.}
\end{center}
\end{slide}

\end{document}

Result:

enter image description here 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.