[Tex/LaTex] Itemise within a caption doesn’t work

captionsitemize

I've been trying to figure this out, but while I did find another thread with the same problem, I didn't understand what they specifically did to solve it. So I'm using the package

\usepackage{caption}

And want to have the following figure with a caption:

\begin{figure}
 \centering
 \includegraphics[scale=0.47]{HP.png}
 \captionsetup{singlelinecheck=off}
 \caption{
  text1:

  \begin{itemize}
   \renewcommand\labelitemi{--}
   \item blue: $0.1 - 0.36$
   \item green: $0.36 - 0.98$
   \item red: $0.98 - 3.5$
   \item purple: $3.5 +$
  \end{itemize}

  text2 }
 \label{HP}
\end{figure}

And it gives me this error:

! Argument of \@caption has an extra }.

The other solution did something, but I couldn't figure out what, since they were using "foo" "bar" instead of real commands.

UPDATE: with the proposed solution below

\begin{figure}
  \centering
  \includegraphics[scale=0.3]{HP.png}
  \captionsetup{singlelinecheck=off}
  \caption[]{text1:

    \begin{itemize}[label={--}]
      \item blue: 0.1 -- 0.36
      \item green: 0.36 -- 0.98
      \item red: 0.98 -- 3.5
      \item purple: 3.5 +
    \end{itemize}

    text2}
\end{figure}

I now get error ! LaTeX Error: Something's wrong--perhaps a missing \item.

Can anyone else try it and see if they get the same error?

Best Answer

Note that the caption is a floating argument, and they are fragile. With singlelinecheck=off there is some safety, but you should supply a non-paragraph caption as the floating argument:

enter image description here

\documentclass{article}

\usepackage{caption,graphicx,enumitem}

\begin{document}

\begin{figure}
  \centering
  \includegraphics[scale=0.3]{example-image}
  \captionsetup{singlelinecheck=off}
  \caption[]{text1:

    \begin{itemize}[label={--}]
      \item blue: 0.1 -- 0.36
      \item green: 0.36 -- 0.98
      \item red: 0.98 -- 3.5
      \item purple: 3.5 +
    \end{itemize}

    text2}
\end{figure}

\end{document}

Note the use of the optional argument that doesn't contain any paragraphs. It's currently blank, which doesn't matter if you're not using \listoffigures.

Related Question