[Tex/LaTex] Wrong \ref to chapters in appendix

cross-referencing

I have a document where I want to include some questionnaires in the appendix (each questionnaire in a new chapter). The text contains crossreferences to the chapters in the appendix:

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[main=american]{babel}
\usepackage[pdftex]{hyperref}
\usepackage{prettyref}
\usepackage{lipsum}

\newrefformat{app}{Appendix~\ref{#1}}

\begin{document}

\chapter{Dummy chapter}
\lipsum (See \prettyref{app:A})

\appendix
\chapter{First chapter of appendix}\label{app:A}
\lipsum

\end{document}

The example above works, and in place of the crossreference I get "(See Appendix A)".

Now, my questionnaires are all existing PDF-files. I've split them into individual pages with pdftk and included each page with \includegraphic. Because the pages from the included PDFs fill an entire page, using the normal \chapter{} command is not good — it would result in the chapter title on the top of one page, with the first PDF-page on the following page.

Therefore, I have defined a command \appchap that centers the chaptertitle horizontally and vertically on a page, puts an entry into the TOC, and sets the label:

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[main=american]{babel}
\usepackage[pdftex]{hyperref}
\usepackage{prettyref}
\usepackage{lipsum}

\newcommand{\appchap}[1]{%
    \cleardoubleoddemptypage
    \thispagestyle{empty}
    \vspace*{\fill}%
    \begin{center}
        \usekomafont{disposition}%
        \stepcounter{chapter}%
        \phantomsection\label{app:\thechapter}%
        \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
        \markboth{Appendix~\thechapter: #1}
                 {Appendix~\thechapter: #1~}%
        Appendix~\thechapter:\\[.2\baselineskip]#1%
    \end{center}
    \vfill
    \clearpage
}

\newrefformat{app}{Appendix~\ref{#1}}

\begin{document}

\chapter{Dummy chapter}
\lipsum (See \prettyref{app:A})

\chapter{Another chapter}
\lipsum

\appendix
\appchap{First chapter of appendix}
\lipsum

\end{document}

This works kind of — I get a hyperlink to the correct chapter, but the link text is wrong: Instead of "(See Appendix A)", I get "(See Appendix 2)". Apparently, the chapter number is not set correctly, the number shown is always that of the last chapter before the appendix. What could be wrong with my code?

Best Answer

you probably want

\refstepcounter{chapter} 

not

\stepcounter{chapter} 

but the code looks odd using section numbers (or letters) in a \label argument is almost always the wrong thing to do.

Related Question