3

I´m trying to add a caption under a image that is to the right of an item list. The caption appears but it doesn´t say figure x: Enter Caption Here. How do I do this?

This is the code I´m using:

\begin{minipage}[l]{0.45\textwidth}

\begin{itemize}
    \item Item 1
    \item Item 2
    \item Item 3
    \item Item 4
\end{itemize}

\end{minipage}

\hfill

\begin{minipage}[r]{0.45\textwidth}

\centering

\includegraphics[width=1\textwidth]{}

\caption{Enter Caption Here}

\end{minipage}
4
  • You can't use the caption command outside of a figure or table environment.
    – leandriis
    Apr 7, 2020 at 12:58
  • 1
    If you want the combination if image and list to float, just enclose both and the caption in a figure environment. If you don't want them to float, add the caption package to your preamble and use the \captionof{figure}{enter caption here} command instead.
    – leandriis
    Apr 7, 2020 at 12:59
  • In order to show list and image side-by-side, you will also have to comment out or remove the empty lines around the \hfill command.
    – leandriis
    Apr 7, 2020 at 13:02
  • You should get an error message such as: \caption outside float. As soon as you get an error message, do not look at the outpu. Even if you get something that on first glance resembles a pdf file, there can still be issues with it. After an error, TeX only tries to recover enough to syntax check more of the file, it does not try to make sensible output after an error.
    – leandriis
    Apr 7, 2020 at 13:03

2 Answers 2

4

Welcome here !

First things first, it's easier to help you if you provide a complete MWE. For the following, I suppose you're using article class.

There are some problems in your snippet code we have to tackle first :

  • If you want minipage environment next to each other, you've to remove the line spaces around \hfill. With a blank line, LaTeX will insert a blank line.
  • If you compile, the log file pointed to an error : ! LaTeX Error: \caption outside float.. This message means that you cannot use \caption{} outside a float environment like figure or table. Therefore, you have to use either a figure environment or the package caption to use the command \captionof{figure}{}. This is the solution I proposed here.
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption} %%numbered caption outside floats

\begin{document}
 \begin{minipage}[l]{0.45\textwidth}
     \begin{itemize}
         \item Item 1
         \item Item 2
         \item Item 3
         \item Item 4
     \end{itemize}
 \end{minipage}
 \hfill          %%Remove blank lines here
 \begin{minipage}[r]{0.45\textwidth}
     \centering
     \includegraphics[width=1\textwidth]{example-image-a}
     \captionof{figure}{Enter Caption Here}  %%\captionof{figure} instead of \caption{}
 \end{minipage}
\end{document}

Output :

enter image description here

2
  • @Vincent Thank you for editing, i've encountered some troubles with code markers !
    – Piroooh
    Apr 7, 2020 at 13:14
  • No problem ! :)
    – Vincent
    Apr 7, 2020 at 13:31
3

Another solution to get the output you're looking for is to use the wrapfigure environment from the wrapfig package.

Here's an example.

\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}

\begin{wrapfigure}{r}{0.45\textwidth}
\centering
\includegraphics[width=1\linewidth]{example-image}
\caption{Enter Caption Here}
\end{wrapfigure}

~ %Used here because a wrapfigure environment cannot be placed directly before a list environment.
\begin{itemize}
    \item Item 1
    \item Item 2
    \item Item 3
    \item Item 4
\end{itemize}

\end{document}

2
  • I would be carful when combining list-like environments with wrapfigsince the wrapfig documentation explicitly states: "You must not specify a wrapfigure in any type of list environment or or immediately before or immediately after one. It is OK to follow a list if there is a blank line (\par) in between."
    – leandriis
    Apr 7, 2020 at 13:40
  • 1
    @leandriis Yes, it's indeed a good idea to be careful (in fact, I must say that I learned to be somewhat careful whenever I use a wrapfigure). However, as far as I know, it can work perfectly well depending on the actual content of the list, as it does in this example.
    – Vincent
    Apr 7, 2020 at 13:54

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.