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:
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?
\caption{\protect\dbox{Boxed text} in caption.}ā egreg Aug 13 '19 at 10:29