Compilation error: Argument of \sf@@@subfloat has an extra }. Besite it works well

I would like to fix errors of compilation, but I do konw how. I would like to could still using labels.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{subfig}
\usepackage{graphicx}

\begin{document}
some text \ref{fig:label0}\\
some text \ref{fig:label1}\\
some text \ref{fig:label2}\\
some text \ref{fig:label3}\\

\begin{figure}[h]%
\centering
\subfloat[{\centering description A}]{\includegraphics[width=0.33\textwidth]{tmp_img.eps}
\label{fig:label1}}%
\subfloat[{\centering description B}]{\includegraphics[width=0.33\textwidth]{tmp_img.eps}
\label{fig:label2}}%
\subfloat[\centering description C]{\includegraphics[width=0.33\textwidth]{tmp_img.eps}
\label{fig:label3}}%
\caption{Main}
\label{fig:label0}%
\end{figure}

\end{document}


  Argument of \sf@@@subfloat has an extra }.

<inserted text>
\par  l.18 \label{fig:label1}}
% I've run across a }' that doesn't seem to match anything.
For example, \def\a#1{...}' and \a}' would produce
this error. If you simply proceed now, the \par' that I've just
inserted will cause me to report a runaway argument that might be the
root of the problem. But if your }' was spurious, just type 2' and
it will go away.

Runaway argument? {\centering description A}]{\@firstoftwo {\nobreak
\@xcentercr }}\def \ETC. ! Paragraph ended before \sf@@@subfloat was
\par  l.18 \label{fig:label1}}
%
I suspect you've forgotten a }', causing me to apply this control sequence to too much text.
How can we recover?
My plan is to forget the whole thing and hope for the best.


Result of this code looks like this:

• If I use example-image on an up to date texlive 2019 then this gives no errors, although you get a warning about the bad \\  after \ref{fig:label3} – David Carlisle Oct 30 '19 at 14:49
• @DavidCarlisle Interesting: I do get the error with TeXLive2017. – campa Oct 30 '19 at 15:57
• @campa pre-history:-) – David Carlisle Oct 30 '19 at 15:59
• @DavidCarlisle Sad reality for me. I can't have an up-to-date distribution on the university PC. But what could have changed? I believe subfig hasn't been touched for a while, so it must (?) have to do with the kernel... – campa Oct 30 '19 at 16:02
• @campa fragile command in moving argument answer posted.... – David Carlisle Oct 30 '19 at 16:10

It's not the problem of the label. Rather you should remove \centering from the subfloat description.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{subfig}
\usepackage[demo]{graphicx}

\begin{document}
some text \ref{fig:label0}\\
some text \ref{fig:label1}\\
some text \ref{fig:label2}\\
some text \ref{fig:label3}\\

\begin{figure}[h]%
\centering
\subfloat[description A]{\includegraphics[width=0.33\textwidth]{tmp_img.eps}\label{fig:label1}}%
\hfill
\subfloat[description B]{\includegraphics[width=0.33\textwidth]{tmp_img.eps}\label{fig:label2}}%
\hfill
\subfloat[description C]{\includegraphics[width=0.33\textwidth]{tmp_img.eps}\label{fig:label3}}%
\caption{Main}
\label{fig:label0}%
\end{figure}

\end{document}


• That works! But when i use very long description, eg. Lorem Ipsum is simply dummy text of the printing and typesetting industry it is not readeble How I can make space between columns, to make it more readabe? – nanose Oct 30 '19 at 16:06

In the current LaTeX release the document posted in the question runs without error, but in older releases \centering was fragile so you need to use \protect as follows:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{subfig}
\usepackage{graphicx}

\begin{document}
some text \ref{fig:label0}\\
some text \ref{fig:label1}\\
some text \ref{fig:label2}\\
some text \ref{fig:label3}% no\\

\begin{figure}[htp]%
\centering
\subfloat[{\protect\centering description A}]{\includegraphics[width=0.33\textwidth]{example-image}
\label{fig:label1}}%
\subfloat[{\protect\centering description B}]{\includegraphics[width=0.33\textwidth]{example-image}
\label{fig:label2}}%
\subfloat[\protect\centering description C]{\includegraphics[width=0.33\textwidth]{example-image}
\label{fig:label3}}%
\caption{Main}
\label{fig:label0}%
\end{figure}

\end{document}

• Ah, of course... should have thought of that :-) – campa Oct 30 '19 at 16:22
• This works too! But I changed my criteria :D As I mentioned in comment problem is when in description is too long text. I have similar error when I try to use \begin{minipage}{0.3\textwidth} Lorem Ipsum is simply dummy text of the printing and typesetting industry \end{minipage} – nanose Oct 30 '19 at 16:27
• @nanose well that will be the same. It will work in current releases but need \protect\begin and \protect\end` in old ones. – David Carlisle Oct 30 '19 at 16:42