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}
Rainymood
  • 145
  • 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 09:38
  • This question should not have the beamer tag, imho. – Johannes_B Feb 19 '18 at 09:46
  • @Johannes_B Already changed that :) – samcarter_is_at_topanswers.xyz Feb 19 '18 at 09:47
  • just use \includegraphics{foo} – David Carlisle Feb 19 '18 at 10:05
  • @DavidCarlisle I want a caption, that's the whole point. Sorry, I was not explicit about this enough. I will change this. – Rainymood Feb 19 '18 at 10:41
  • @Marijn Thank you, I will try your suggestion – Rainymood Feb 19 '18 at 10:41
  • @Marijn I do not seem able to get captionof working, would you mind writing out a small example? I get the error " l.87 \captionof{figure}{ this is my caption} If you do not understand this error, please take a closer look .." which is not very helpful. I've looked on the internet but it doesn't seem like a widly used preset (slides, instead of beamer) – Rainymood Feb 19 '18 at 10:51
  • that is not the whole error message, the full error probably says undefined command. Why does it need to be a "caption" rather than just a paragraph under the image? Note slides class is part of the core latex distribution but basically it is not recommended for any presentations given this century, it made sense in 1985, but less so now. – David Carlisle Feb 19 '18 at 11:01
  • 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

1 Answers1

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

Marijn
  • 37,699