# Reference to figures in appendix is not printed properly

When citing a figure in a section in my report body, the reference prints the correct number:

 Figure\ref{fig:UML} illustrates complexity arising from the non-modularity of the existing design:

Figure 5.1.1 illustrates complexity arising from the non-modularity of the existing design:


However, the reference in my appendices fails to print out the reference in the same manner:

 \appendix
\backmatter
%...
Figure \ref{fig:mvcmodel} is a visual representation of the pattern:

Figure B is a visual representation of the pattern:


I am currently using chngcntr package to number my figures and tables in my \listoffigures and \listoftables, and I want the reference in appendices to follow the same numbering scheme as my table of contents.

I am attaching my document class:

  \let\appendix@rig\appendix
\renewcommand{\appendix}{%
\@mainsect%
\ifthenelse{\boolean{uwwkrpt@math}}{%
\renewcommand{\@secdotzeroend}[1]{}
}{}%
\ifthenelse{\boolean{uwwkrpt@ece}}
{\renewcommand{\@appendixtitle}{Appendix }}{}
\appendix@rig%
}
\newcommand{\backmatter}{%
\clearpage
\@notmainsect%
\ifthenelse{\boolean{uwwkrpt@math}}%
{\renewcommand{\section}{\clearpage\section@rig}}{}%
}

-
What documentclass do you use? (Hint: It works for me with the report class.) Also, do I understand correctly that you get "Figure B" but want "Figure B.1.1"? – lockstep May 2 '11 at 16:25
I am using my own document class which follows my faculty requirements for a technical report. And, yes I do want Figure B.1.1 to be printed for my figure reference. Thank you. – Midnight Blue May 2 '11 at 16:29
I strongly suspect that your class messes around with \appendix. Try to include \counterwithin{figure}{section} a second time after \appendix. If that doesn't help, you have to make the class file available. – lockstep May 2 '11 at 16:35
Seeing "Figure B" as a reference, I suspect a wrong order of \label and \caption: the former should be always after the latter. – egreg May 2 '11 at 21:22

A \caption command is required for referencing to the label. If you don't have a caption, the reference would point to the most recent possible place, which can be the section containing the figure. Here you are in the appendix and in section B, so you would get the reference to B.

If you don't use \caption and \label in the right order (\caption at first), it would have the same effect, as egreg commented.

The problem is very similar to the one in this question: autoref points to section instead of figure or table.

-