0

I’m trying to use a \dbox from the dashbox package in the caption of a figure, like this:

\documentclass{article}

\usepackage{dashbox}

\begin{document}
    \begin{figure}
        \centering Imagine some figure here

        \caption{\dbox{Boxed text} in caption.}
    \end{figure}
\end{document}

The result I get looks like expected:Dashbox in caption However, I get plenty of errors:

Undefined control sequence. \caption{\dbox{Boxed text} in caption.}
Undefined control sequence. \caption{\dbox{Boxed text} in caption.}
Illegal parameter number in definition of \reserved@a. \caption{\dbox{Boxed text} in caption.}
Extra \or. \caption{\dbox{Boxed text} in caption.}
...

The package documentation says:

\dbox{text} works like \fbox, but the box is drawn with dashed lines.

But \fbox works fine inside a caption.

The boxes from the fancybox package seem to have similar problems.

What is the correct way to draw a dashed box in a caption?

  • 2
    Use \caption{\protect\dbox{Boxed text} in caption.} – egreg Aug 13 at 10:29
  • Thanks, this solved my problem. – Roman Langrehr Aug 13 at 10:32
0

If an alternative text for the list of figures is provided, \dbox can be used without further ado

\documentclass{article}

\usepackage{dashbox}

\begin{document}
    \begin{figure}
        \centering Imagine some figure here

        \caption[text for list of figures]{\dbox{Boxed text} in caption.}
    \end{figure}
\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.