Using \subref in the caption of a figure (LaTeX)

I use the subfig package and when I compiled my thesis in Linux I encountered a problem, when I used the \subref command in the caption of a figure. The compilation was stopped with the error message “Argument of \@tempf has an extra }.”

Scanning the internet I found this forum entry in German where it was proposed to add the command “\protect” before “\subref{fig:1}, which actually did the trick for me. I didn’t have this problem though with MikTeX.

8 thoughts on “Using \subref in the caption of a figure (LaTeX)

  1. I just came across the exact same problem while writing on my thesis and Google brought me directly to your solution here. Thanks! 🙂

  2. I had a different error message, but the problem was similar. And your solution worked. Thanks!

    ! Use of \caption@@settype doesn’t match its definition.
    \new@ifnextchar …served@d = #1\def \reserved@a {
    #2}\def \reserved@b {#3}\f…

    Amy

  3. I had a similar problem…putting \protect in front of the argument works!

    You can’t imagine how much you helped me! Thanks a lot! 🙂

  4. Saved my day, the thesis that compiled fine on Linux returned these weird errors on Windows, \protect before \subref{} solved everything.

    Thank you.

  5. Hello everyone !
    \protect is a very useful command, but I did it and I still have some problems. The file is compiled, but in the legend I just obtain ?? instead of a) and b).
    Do you know the reason of this ?
    In my code, I open a “figure” environnement and inside there are two “minipage” environnements. The label for each is placed the line before the “\end{minipage}” for both.
    Any idea ?
    Thanks !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.