4

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}
3
  • 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, 2011 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, 2011 at 7:10
  • 2
    Also please keep it a minimal working example (MWE), i.e. replace or remove the \include{Titel}. Oct 17, 2011 at 7:21

1 Answer 1

8

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}
4
  • 1
    @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. Oct 17, 2011 at 7:31
  • 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, 2011 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. Oct 17, 2011 at 7:45
  • @MartinScharrer cool thank you! I'll have a look at your links
    – strauberry
    Oct 17, 2011 at 7:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .