[Tex/LaTex] Dashed underline in caption using ulem

captionsulem

I'm trying to dashed underline a word in a caption using the ulem package. While the \dashuline{} command works fine everywhere else, I get "Undefined control sequence" as error message in caption.

\begin{figure}
    While it does work \dashuline{here}
    \caption{It does not work \dashuline{here}}
\end{figure}

Has anyone an idea why it doesn't work and how to get it working?

Best Answer

Protecting the command should solve the problem:

\documentclass{article}

\usepackage{ulem}

\begin{document}

\begin{figure}
    While it does work \dashuline{here}
    \caption{It does not work \protect\dashuline{here}}
\end{figure}

\end{document}

enter image description here

Related Question