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.

In my document, I have some figures in my appendix I want to reference in my text but the output of \ref{} is only "Figure .2 shows...". It should be something like "Figure B.2".

Here's my minimal example:

\documentclass[bibliography=totoc,index=totoc,numbers=noenddot]{scrbook}
\usepackage[demo]{graphicx}
\begin{document}

\frontmatter
    \include{Titel}
    \tableofcontents

\mainmatter
    Here is my text \ref{fig:XYZ}

\backmatter
\appendix
\renewcommand\thesection{\Alph{section}}
\chapter{Appendix}
\section{UML-Diagrams}
\begin{figure}[h]
  \begin{center}
    \includegraphics[width=15cm]{xyz.jpg}
    \caption{\label{fig:XYZ}XYZ}
  \end{center}
\end{figure}

\end{document}
share|improve this question
1  
I've added the line \usepackage[demo]{graphicx} to your MWE, as it doesn't compile otherwise. The [demo] option replaces images with black rectangles, so compilation doesn't fail because of missing images. I can't reproduce the behaviour you describe, however. I get the output Here is my text 1, and the figure caption is Figure 1: XYZ. –  Jake Oct 17 '11 at 7:06
    
Thank you for your editing! Wired that you get the semi-correct output?! I'd like to have it A.1 anyway. –  strauberry Oct 17 '11 at 7:10
2  
Also please keep it a minimal working example (MWE), i.e. replace or remove the \include{Titel}. –  Martin Scharrer Oct 17 '11 at 7:21
add comment

1 Answer

up vote 7 down vote accepted

You also need to redefine \thefigure to your own format. By default scrbook removes the chapter number from it outside the main matter. I assume now you actually want the section number in it.

Also note that you should use \centering not the center environment in floats like figure. Then {figure}[h] is never a good idea. If you don't want to make the figure float use an own environment (like center which now is OK) instead and use \captionof{figure}{...} for the caption (needs either the caption (big) or capt-of (small) package). Also, please put the \label after \caption, not inside it. It works both ways but this is better.

\documentclass[bibliography=totoc,index=totoc,numbers=noenddot]{scrbook}
\usepackage[draft]{graphicx}
\usepackage{capt-of}
\begin{document}

\mainmatter
Here is my text \ref{fig:XYZ}

Here is my text \ref{fig:XYZ2}

\backmatter
\appendix
\renewcommand\thesection{\Alph{section}}
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\chapter{Appendix}
\section{UML-Diagrams}

\begin{center}
    \includegraphics[width=15cm]{xyz.jpg}
    \captionof{figure}{XYZ}\label{fig:XYZ}
\end{center}

\begin{figure}
    \centering
    \includegraphics[width=15cm]{xyz.jpg}
    \caption{XYZ2}\label{fig:XYZ2}
\end{figure}

\end{document}
share|improve this answer
    
@Jake: As always, if you know what to do you can do it. But many beginners seems to not understand the principle behind floats and try to force some Word-like behavior by default. –  Martin Scharrer Oct 17 '11 at 7:31
    
Okay, thank you! –  Jake Oct 17 '11 at 7:34
    
The renewing of the command thefigure does the job, thank you very much! A very good hint with the centering-environment, but I did not get your point :-) Could you explain it again for me? Thank you! –  strauberry Oct 17 '11 at 7:36
2  
@strauberry: The center environment adds additional space before and after it, while the \centering macro doesn't. See Should I use center or centering for figures? for more infos. See also Label and caption without float for the other tip I mentioned. –  Martin Scharrer Oct 17 '11 at 7:45
    
@MartinScharrer cool thank you! I'll have a look at your links –  strauberry Oct 17 '11 at 7:51
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.