How to put figure between items on enumerate list?
Asked Answered
D

3

10

I have an enumerate list and some items have figures. My code follows below:

\begin{enumerate}
    \item Estado da arte: 
    \item Levantar os requisitos
    \item Com o microcontrolador
\ref{figurametodo3}.    
    \begin{figure}[h!]
        \begin{center}
            \includegraphics[scale=0.6]{./dados/figuras/metodo_3}
            \caption{Sistema para leitura da identificação de uma Tag} 
            \label{figurametodo3}
        \end{center}
    \end{figure}
    
    
    \item Estudar
            
    \begin{figure}[h]
    \begin{center}
        \includegraphics[scale=0.4]{./dados/figuras/metodo_4}
        \caption{Comunicação entre o microcontrolador e o celular} 
        \label{figurametodo4}
    \end{center}
\end{figure}
    
    \item Desenvolver 
    
    \begin{figure}[h]
    \begin{center}
        \includegraphics[scale=0.6]{./dados/figuras/metodo_final}
        \caption{Comunicação entre celulares e servidor} 
        \label{figura22}
    \end{center}
\end{figure}
            
\end{enumerate}

However it aligns all the figures below the list: outside of the places that I want. I want that my figures stay just below that item: within the list.

Dichromaticism answered 22/6, 2018 at 19:29 Comment(0)
I
13

This is covered in the following FAQs:

Here's one option using the float package and it's [H]ERE float specifier:

enter image description here

\documentclass{article}

\usepackage{float,graphicx}

\begin{document}

\begin{enumerate}
  \item Item 1
  \item Item 2
  \item Item 3

  \begin{figure}[H]
    \centering
    \includegraphics[width = .5\linewidth]{example-image-a}
    \caption{A figure caption}
  \end{figure}

  \item Item 4

  \begin{figure}[H]
    \centering
    \includegraphics[width = .5\linewidth]{example-image-b}
    \caption{B figure caption}
  \end{figure}

  \item Item 5
  \item Item 6
\end{enumerate}

\end{document}
Interruption answered 26/6, 2018 at 0:54 Comment(0)
K
8

Use minipage environment to insert the image:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\begin{document}
\begin{enumerate}
  \item Estado da arte:
  \item Levantar os requisitos
  \item
    \begin{minipage}[t]{\linewidth}
      Com o microcontrolador \newline                                
      \includegraphics[scale=0.6]{./dados/figuras/metodo_3}
      \captionof{figure}{Sistema para leitura da identificação de    uma Tag}
    \end{minipage}

\end{enumerate}
\end{document}

You should not use figure, if you don't want a float.

The LaTeX Wikibook explains:

Floats are containers for things in a document that cannot be broken over a page. LaTeX by default recognizes "table" and "figure" floats, [...]. Floats are there to deal with the problem of the object that won't fit on the present page, and to help when you really don't want the object here just now.

To provide a caption outside of figures one needs to use package caption, which provides the captionof command.

There is also a capt-of package if you are just interested in using the command \captionof.

Keystone answered 25/6, 2018 at 19:6 Comment(0)
M
2

The answer by Werner is nice but you do have to type in the mandatory "Item 3" besides the "\item" command, for example. Supposing you just want to include a figure on an item on the list without adding any text, there is the following dirty trick:

\item \phantom{text}

\includegraphics[scale=0.5]{Image}
    

Note that the blank space between these two lines of code is absolutely necessary. In case you want more space between the item label and the diagram, the following could be done:

\item \phantom{text} 
\vspace{3mm}
    
\includegraphics[scale=0.5]{Image}
Marcelmarcela answered 1/1, 2023 at 11:57 Comment(1)
Can you explain why this trick works?Pastypat

© 2022 - 2024 — McMap. All rights reserved.