\begin{figure} Your command was ignored using the slides preset

\begin{figure} Your command was ignored using the slides preset

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}

답변1

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

관련 정보