Graphics, Figures & Tablessubfig captions referencing subfigures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

subfig captions referencing subfigures

Post by daviddoria »

When trying to use \subref in a subfloat caption, I am getting "Argument of caption has an extra}". I am following the subfig documentation for doing this, so I think the syntax is correct. Any ideas? An example (working and broken version) is below:

Code: Select all

\documentclass{article}

\usepackage{subfig}

\begin{document}
 
% this works
% \begin{figure*}[tb]
% \centering
% \subfloat[]{
% \fbox{\rule{0pt}{2in} \rule{0.9\linewidth}{0pt}}
% \label{fig:CatOcclusion:None}
% }
% \end{figure*}

\begin{figure*}
\centering
\subfloat[]{
\fbox{\rule{0pt}{2in} \rule{0.9\linewidth}{0pt}}
\label{fig:CatOcclusion:None}
}

\caption{Cat sculpture scans with varying occlusions. \subref{fig:CatOcclusion:None} No occlusion} % this is the line with the problem
%\caption{Cat sculpture scans with varying occlusions} % works
\end{figure*}

\end{document}
Thanks,

David
Last edited by daviddoria on Sat Feb 25, 2012 7:37 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

subfig captions referencing subfigures

Post by Stefan Kottwitz »

Also here, it works without error for me.
subref.png
subref.png (6.9 KiB) Viewed 9280 times
Perhaps post again a .log file.
Btw. better use the Code button in a forum post, the LaTeX button is for inline code.

Stefan
LaTeX.org admin
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Re: subfig captions referencing subfigures

Post by daviddoria »

Log file attached. (and I changed the to [code] in the original post.

Thanks you very much for your help so far!
Attachments
test_figure2.log
(4.53 KiB) Downloaded 572 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

subfig captions referencing subfigures

Post by Stefan Kottwitz »

Very good!

In your code, you just need to protect \subref:

Code: Select all

\protect\subref{fig:CatOcclusion:None}
This prevents \subref from being expanded too early, when it's written to the list of figures file.

Stefan
LaTeX.org admin
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Re: subfig captions referencing subfigures

Post by daviddoria »

Strange, I swear I've done that before without \protect, but it indeed works now, thanks again!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: subfig captions referencing subfigures

Post by Stefan Kottwitz »

You are right, with an older caption package (of 2010) it used to work without \protect.

Stefan
LaTeX.org admin
Post Reply