5

I have tried to applied following solution How can I prevent new-line after all items in enumeration? inside a caption of a figure, but I am having an error as follows:

! Missing number, treated as zero.
<to be read again>
                   \c@*

My example code:

\documentclass{article}
\usepackage{tikz}
\usepackage[inline]{enumitem}
\usetikzlibrary{shapes}
\usetikzlibrary{calc}
\begin{document}
\pagestyle{empty}
\begin{figure}
\begin{tikzpicture}
    \node[text width=1cm,text centered] (A) [cylinder, shape border rotate=90, draw,minimum height=0.5cm,minimum
        width=0.5cm, shape
        aspect=0.4,execute at begin node=\setlength{\baselineskip}{8pt}]{\scriptsize{Cloud Storage}};
    \end{tikzpicture}
    \caption{Hello:
        \begin{enumerate*}[label=(\arabic*),itemjoin=\quad]
            \item[(\textit{i})] The first item
            \item[(\textit{ii})] Second item
            \item[(\textit{iii})] Third item
            \item[(\textit{iv})] Third item.
        \end{enumerate*}
    }
\end{figure}
\end{document}

when I comment out following lines it works fine:

        \begin{enumerate*}[label=(\arabic*),itemjoin=\quad]
            \item[(\textit{i})] The first item
            \item[(\textit{ii})] Second item
            \item[(\textit{iii})] Third item
            \item[(\textit{iv})] Third item.
        \end{enumerate*}

Is it possible to use enumerate inside a caption of a figure?

alper
  • 1,389

1 Answers1

5

The mandatory argument to \caption (delimited with curly brackets) will not only be printed at the relevant position, but it will also be stored to be used at other places in your document, for example in the table of contents or for the bookmarks of the PDF. Therefore, you need to be cautious when inserting macros here.

You can provide a non-macro version of the caption which is used at the other places in the document by using the optional argument (delimited with square brackets) of the \caption macro:

\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document} \pagestyle{empty} \begin{figure} \begin{tikzpicture} \node[text width=1cm,text centered] (A) [cylinder, shape border rotate=90, draw,minimum height=0.5cm,minimum width=0.5cm, shape aspect=0.4,execute at begin node=\setlength{\baselineskip}{8pt}]{\scriptsize{Cloud Storage}}; \end{tikzpicture} \caption[Hello: An inline description of the list.]{Hello: \begin{enumerate}[label=(\textit{\roman}),itemjoin=\quad] \item The first item \item Second item \item Third item \item Third item. \end{enumerate*} } \end{figure} \end{document}

enter image description here

  • 2
    \textit{(iv)} ? – David Carlisle Aug 06 '22 at 10:32
  • Better even, use label=(\roman*) (or similar) and don’t put labels explicitly. – Jasper Habicht Aug 06 '22 at 10:42
  • @JasperHabicht I wanted to use label=(\roman*) but some cases I had to do (ii-v) to cover multiple roman numbers that's why I was not able to stick with label=(\roman*) – alper Aug 06 '22 at 10:50
  • 1
    You can set the counter. See https://tex.stackexchange.com/q/142/47927 – Jasper Habicht Aug 06 '22 at 10:51
  • Note: This will remove this figure from the "List of figures", as mentioned in https://tex.stackexchange.com/questions/380284/using-enumerate-environment-in-a-figure-caption#comment1106490_380294 . May be important when writing a thesis of so. – Johannes Feb 25 '24 at 09:36