20

I'm trying to put an image with a caption on it within an itemize environment (within another itemize environment). When I had the image with no caption, simply using \includegraphics, it indented to the same level as the other elements of the itemize list. However, when I wrapped it in a figure environment because I wanted a caption, it is indented to the left margin, completely sticking out of the list.

Here's what I've got:

\begin{itemize}
    \item Describing large-scale processor activity.

    \item To discuss digital systems of this scale and level of complexity
    we need a number of descriptive tools.

    \item For example:                                                 

    \begin{itemize}
        \item[a)] Circuit schematics highlight the circuit components and
        their connectivity.

        \begin{figure}[h]

            \includegraphics[width=10cm{assets/fig001.png}
            \caption{Transfer from R1 to R2 whenK1=1}
        \end{figure}
        \item[b)] Timing diagrams highlight the detailed time sequence of
        transfer between registers

        \includegraphics[width=10cm]{assets/fig002.png}

    \end{itemize}
\end{itemize}

Here's the result:

enter image description here

I've tried h, h! and H in the figure positioning, but it stays exactly where it is.

TL;DR: How can I have the first image here indented like the second, but with a caption?

34

Don't use a floating environment (such as figure) if you want your image to appear in the exact position where you write it. You can use a minipage and, if a caption is required, the \captionof command (provided by the capt-of package or by the caption package).

In the following example I illustrate this approach; I also used the `enumitem package to customize the labels for the inner list:

\documentclass{article}
\usepackage[demo]{graphicx}% demo option just for the example
\usepackage{caption}
\usepackage{enumitem}
\begin{document}

\begin{itemize}
    \item Describing large-scale processor activity.
    \item To discuss digital systems of this scale and level of complexity
    we need a number of descriptive tools.
    \item For example:                                                 
    \begin{enumerate}[label=\alph*)]
        \item Circuit schematics highlight the circuit components and
        their connectivity.\par
        \begin{minipage}{\linewidth}
            \centering
            \includegraphics[width=10cm]{assets/fig001.png}
            \captionof{figure}{Transfer from R1 to R2 whenK1=1}
        \end{minipage}
        \item Timing diagrams highlight the detailed time sequence of
        transfer between registers.\par
        \includegraphics[width=10cm]{assets/fig002.png}
    \end{enumerate}
\end{itemize}

\end{document}

enter image description here

0

When using the solution of Gonzalo Medina, hypcap doesn't know where the actual figure is. The hyperlink in the List of Figures links to the caption directly instead of the top of the figure.

That's why this error is thrown:

Package caption warning: The option 'hypca=true' will be ignored....

A better solution is using \caption in combination with \captionsetup{type=figure} above \includegraphics. That marks the beginning of the figure and allows the use of \caption outside of float environments.

An example:

\documentclass{book}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{caption}
\begin{document}
    \listoffigures
    \newpage
    \chapter{List}
    \begin{itemize}
        \begin{minipage}{\linewidth}
            \item
                \captionsetup{type=figure}
                \includegraphics[width=0.5\linewidth]{picture}
                \caption{text}      
        \end{minipage}
    \end{itemize}
    \newpage
    Add space.
\end{document}

I found the solution in this and this German source.

  • 2
    Welcome to TeX.SE! Please translate your answer into english, that is the language used here! – Mensch Aug 30 at 15:24
  • 1
    I'm very sorry, I switched between English and German sources too many times and didn't realize I was writing in the English community :S – ro-bb Sep 3 at 13:45

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.