# Caption shifted left with \captionof in a list environment

I use the \captionof command from the caption package within a list environment. I would expect the caption to be centered with respect to the page, or to move right because of the indentation of the lists. However, the caption is shifted to the left (see example below, with four lists to exagerate the problem). How can this be fixed?

\documentclass{article}
\let\oldcaption\caption
\usepackage{caption}
\begin{document}
\begin{figure}
Within a float:
\oldcaption{Default \LaTeX's caption. OK.}
\end{figure}
\begin{figure}
Within a float:
\caption{\textsc{Caption}'s \texttt{\string\caption}. OK.}
\end{figure}
\noindent Outside of a float:
\bgroup
\captionof{figure}{\textsc{Caption}'s \texttt{\string\captionof}. OK.}
\egroup
\begin{itemize}
\item
\begin{itemize}
\item
\begin{itemize}
\item
\begin{itemize}
\item
\begin{figure}[h]
Within a float, within lists:
\caption{\textsc{Caption}'s \texttt{\string\caption}. OK.}
\end{figure}
\noindent
Outside of a float, within lists:
\bgroup
\captionof{figure}{\textsc{Caption}'s \texttt{\string\captionof}. Left shift.}
\egroup
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}
\end{document}


I don't know the reason of this behavior, but if you put your \captionof inside a \parbox of width \linewidth

\parbox{\linewidth}{\captionof{figure}{\textsc{Caption}'s \texttt{\string\captionof}. Left shift.}}


the caption is centered in the remaining line width, that is, it is right-shifted as expected:

Full MWE:

\documentclass{article}
\let\oldcaption\caption
\usepackage{caption}
\begin{document}
\begin{figure}
Within a float:
\oldcaption{Default \LaTeX's caption. OK.}
\end{figure}
\begin{figure}
Within a float:
\caption{\textsc{Caption}'s \texttt{\string\caption}. OK.}
\end{figure}
\noindent Outside of a float:
\bgroup
\captionof{figure}{\textsc{Caption}'s \texttt{\string\captionof}. OK.}
\egroup
\begin{itemize}
\item
\begin{itemize}
\item
\begin{itemize}
\item
\begin{itemize}
\item
\begin{figure}[h]
Within a float, within lists:
\caption{\textsc{Caption}'s \texttt{\string\caption}. OK.}
\end{figure}
\noindent
Outside of a float, within lists:

\vspace*{\baselineskip}
\parbox{\linewidth}{\captionof{figure}{\textsc{Caption}'s \texttt{\string\captionof}. Left shift.}}
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}
\end{document}


Also notice that the 4th caption is outside the list... That's probably why you don't encounter that strange behavior.

• Perfect! Just note that in the \par\vspace*{...} before the \parbox, the glue should be \abovecaptionskip rather than \baselineskip. – Michel Fioc Dec 8 '14 at 11:15
• @MichelFioc you're obviously right about \abovecaptionskip ;-) – karlkoeller Dec 8 '14 at 11:27

I have added a \centering at your last caption which seems to fix the problem, although it still doesn't line up with the other captions.

    \documentclass{article}
\let\oldcaption\caption
\usepackage{caption}
\begin{document}
\begin{figure}
Within a float:
\oldcaption{Default \LaTeX's caption. OK.}
\end{figure}
\begin{figure}
Within a float:
\caption{\textsc{Caption}'s \texttt{\string\caption}. OK.}
\end{figure}
\noindent Outside of a float:
\bgroup
\captionof{figure}{\textsc{Caption}'s \texttt{\string\captionof}. OK.}
\egroup
\begin{itemize}
\item
\begin{itemize}
\item
\begin{itemize}
\item
\begin{itemize}
\item
\begin{figure}[h]
Within a float, within lists:
\caption{\textsc{Caption}'s \texttt{\string\caption}. OK.}
\end{figure}
\noindent
Outside of a float, within lists:
\bgroup
\centering\captionof{figure}{\textsc{Caption}'s \texttt{\string\captionof}. Left shift.}
\egroup
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}
\end{document}


Is this a fix for your problem?

• This centers the list, not the caption... – karlkoeller Dec 8 '14 at 10:22
• I seem to have misinterpreted the question, it seems @karlkoeller does provide a working MWE. If his answer fixes your problem, I suggest you accept his feedback as the answer. – Wolhandkrab Dec 8 '14 at 10:36