I'm writing a document involving phasors and I'd like to use egreg's notation from this post: \bar below symbol, e.g. $\underaccent{\bar}{U}$
.
It works well except if I put the phasor inside a caption. This is a MWE:
\documentclass[10pt]{article}
\usepackage{accents}
\usepackage{caption}
\usepackage{tikz}
\begin{document}
\begin{itemize}
\item An ugly phasor: $\underline{U}$.
\item Another, better good-looking phasor: $\underaccent{\bar}{U}$.
\end{itemize}
\begin{figure}[h]\centering
\begin{tikzpicture}
\draw[-latex] (0,0) -- (3,0) node [right] {$\underaccent{\bar}{U}$};
\end{tikzpicture}
\caption{One phasor.}
%\caption{One phasor $\underaccent{\bar}{U}$.} % <-- NOT WORKING
\end{figure}
\begin{center}
\begin{tikzpicture}
\draw[-latex] (0,0) -- (3,0) node [right] {$\underaccent{\bar}{V}$};
\end{tikzpicture}
\captionof{figure}{Another phasor.}
%\captionof{figure}{Another phasor $\underaccent{\bar}{V}$.} % <-- NOT WORKING EITHER
\end{center}
\end{document}
As you can see I tried a workaround with the caption package, but to no avail. I think the relevant lines in my log file are probably the following, but I don't understand them:
! Undefined control sequence.
\cc@@accent #1#2->\let \cc@style
=#1\cc@fetch {#2}\mathaccent \cc@code {\ifc...
! Illegal parameter number in definition of \reserved@a.
I suppose that there is some kind of incompatibility with the accents package and the captions but I haven't seen anything about it in the documentation. Is there a better way to do this?
I'm working with TeX Live 2020, by the way.
\caption[]{One phasor $\underaccent{\bar}{U}$.}
results in the expected output? Likewise\captionof{figure}[]{Another phasor $\underaccent{\bar}{V}$.}
should work.\protect\underaccent{\bar}{U}
, but only without\listoffigures