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.

Possible Duplicate:
Figure numbers using the section number

I have a figure inside a section, like:

\subsection{Something}
\begin{figure}[htbp]
    \centering 
    \includegraphics[height=2in]{pictures/mathematic/vn_vicinity.pdf}
    \hspace{1.5in}\parbox{5in}{\caption{Representación gráfica Vecindad de Von Neumann}}
    \label{fig:VecindadVonNeumann}
\end{figure}

When I want to reference the figure:

This is my all awesome figure \ref{fig:VecindadVonNeumann}

I get the reference number from the section, not from the figure itself.

This is my section number

Section Number

This is my Figure, shows 2.1 as number Figure Number

This is the number that I'm getting in my \ref

2.1.4

Is this normal ? Shouldn't I get 2.1 in my reference ?

share|improve this question
    
You should put the \label command inside the \parbox; however, customizing the appearance of the caption is best done with the caption package. –  egreg Sep 25 '12 at 16:53
add comment

marked as duplicate by David Carlisle, lockstep, cmhughes, Werner, diabonas Sep 25 '12 at 21:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 4 down vote accepted

As soon as you you put the \label inside the \parbox argument, it works fine:

\documentclass{article}
\begin{document}
\subsection{Something}
\begin{figure}[htbp]
\centering 
dummy graphics
\hspace{1.5in}\parbox{5in}{\caption{Representación gráfica Vecindad de Von Neumann}\label{fig:VecindadVonNeumann}}
\end{figure}
This is my all awesome figure \ref{fig:VecindadVonNeumann}
\end{document}

It looks like the \parbox separates the \label from the counter. As @egreg alread pointed out in his comment above, shaping the caption with such \hspace and \parbox things isn't quite good style. Better take the caption package or -- if you use one of them -- the built-in means of the KOMAscript classes.

share|improve this answer
add comment

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