0

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?

  • 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??? – David Carlisle May 14 '16 at 17:50
  • Thanks -- \refstepcounter does the trick! "using section numbers (or letters) in a \label argument is almost always the wrong thing to do???" – Andreas May 14 '16 at 18:05
  • I could have omitted the "almost" :-) – David Carlisle May 14 '16 at 18:10
  • The whole point of label\ref is you use a symbolic name like \label{appendix-about-something} and then \ref{appendix-about-something} provides the correct number whatever number the appendix gets after the document is finally edited. If you do \label{app:\thechapter} then you destroy the whole system as the references break when the number changes because you have added a chapter. – David Carlisle May 14 '16 at 18:13
  • Sorry, sent this comment too early! What I meant to say was "I probably should set the label with a second argument to \appchap. " I'm not the author here: My job is just editing and typesetting this for somebody who wrote his thesis with MS Word. Converting the text to LaTeX is the last step, so everything is already in the right order, and files for image files, tables etc. are named accordingly (e.g. "fig/01.jpg" or "tabs/03.tex"). So, using absolute instead of symbolic names makes it is easier for me to automate things, and not to reference a wrong file. Not the standard case, agreed. – Andreas May 14 '16 at 18:37
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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