Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a document where multiple figures with subfloats are included, like this one:

\documentclass[pdftex, a4paper, oneside]{scrartcl}
\usepackage[lofdepth,lotdepth]{subfig}
\usepackage{graphicx}
\begin{document}
test
\ref{fig:2ref1}
\ref{fig:1ref1}
\section{test}
\begin{figure}[h]
\subfloat[][caption1]{
\includegraphics[width=0.45\textwidth]{pictures/1.pdf}
\label{fig:1ref1}
}
\subfloat[][caption]{
\includegraphics{pictures/2.pdf}
\label{fig:1ref2}
}
\end{figure}
\section{test2}
\begin{figure}[h]
\subfloat[][caption]{
\includegraphics[]{pictures/1.pdf}
\label{fig:2ref1}
}
\subfloat[][captio]{
\includegraphics{pictures/2.pdf}
\label{fig:2ref2}
}
\end{figure}
\end{document}

The problem now is that both \ref{fig:2ref1} and \ref{fig:1ref1} return 1a as picture reference, even if they are different pictures and should be 1a and 2a.

share|improve this question
    
Welcome to TeX.sx! Please add a minimal working example (MWE). The code should be compilable, start with \documentclass{...} and end with \end{document}. –  Jubobs Mar 21 '13 at 12:29
    
Thanks for the hint, hopefully the example should be an minimal example now. –  eactor Mar 21 '13 at 12:56
    
scrartcl doesn't fix my problem if i do so both pictures are named 1a? Instead of 1a and 2a? –  eactor Mar 21 '13 at 14:29
3  
You do not have a \caption{<caption text>} in the first figure, so the figure counter is not incremented, and in the second figure you're still at figure 1. –  Torbjørn T. Mar 21 '13 at 14:37
    
but if i have 5 pictures in one section they can't be all figure one ? how could i distinct then? –  eactor Mar 21 '13 at 14:41
show 1 more comment

2 Answers

up vote 2 down vote accepted

As I mention in comment, the problem is that the figure counter is not incremented, because you do not have a \caption in the figure environments. If you add a caption inside each figure, outside the subfloats, you get the desired outcome.

enter image description here

\documentclass[a4paper, oneside]{scrartcl}
\usepackage[lofdepth,lotdepth]{subfig}
\begin{document}

\ref{fig:1ref1}
\ref{fig:1ref2}

\ref{fig:2ref1}
\ref{fig:2ref2}


\begin{figure}[h]
\centering
\subfloat[][caption1]{
FIGURE 1A
\label{fig:1ref1}
}
\subfloat[][caption]{
FIGURE 1B
\label{fig:1ref2}
}
\caption{First figure}
\end{figure}

\begin{figure}[h]
\centering
\subfloat[][caption]{
FIGURE 2A
\label{fig:2ref1}
}
\subfloat[][captio]{
FIGURE 2B
\label{fig:2ref2}
}
\caption{Second figure}
\end{figure}
\end{document}
share|improve this answer
add comment

The subfig package documentation states, that the command \p@subfigure is prepended to the reference texts and that it defaults to \thefigure. As you don't caption your figures, this is always 1. In the MWE you might want to prepend \thesection instead. So this should help:

\makeatletter
\renewcommand{\p@subfigure}{\thesection}
\makeatother
share|improve this answer
    
I dont even think subfigure package is the same as the subfig package, which replaced the first a while ago? I'm lost .... –  eactor Mar 21 '13 at 15:02
    
Ah sorry, that was my mistake. I meant the subfig package, that OP used. Changed it. –  Toscho Mar 21 '13 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.