3

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}

2 Answers 2

3

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:

enter image description here

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.

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

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?

2
  • This centers the list, not the caption... Commented Dec 8, 2014 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. Commented Dec 8, 2014 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .