7

I have an appendix with sections, e.g. section*{Appendix 1: Measurment of X.Y.}. I have set a label with \label{appendix:1}. Now if I reference that appendix via \ref{appendix:1} I get the number of the last numbered chapter before the appendix. This is because my appendix is also an unnumbered chapter. In my text I want the number of the appendix (each section* is a new appendix here) to be shown, like "in appendix 3 you can see...". How can I do that?

EDIT: Here is a MWE:

\documentclass[
    paper=a4,               
    twoside=true,           
    open=right,             
    fontsize=12pt,              
    parskip,                
    headsepline,            
    cleardoublepage=empty,  
    ]{scrbook}              

\usepackage{scrpage2}       
\pagestyle{scrheadings}     
\automark[section]{chapter}
\clearscrheadings           
\ihead{}                    
\chead{}                    
\ohead{\headmark}           
\ifoot{}                    
\cfoot{}                    
\clearscrplain 
\ofoot[\pagemark]{\pagemark}
\setlength{\headheight}{1.1\baselineskip}

\usepackage[latin1]{inputenc}

\usepackage[
    backend=bibtex,
    ]{biblatex}

\usepackage[pdftex,
            colorlinks,
            linkcolor = black]{hyperref}

\usepackage[titletoc,title]{appendix} 

\begin{document}

\tableofcontents    

\chapter{Just a chapter}
Blabla
\chapter{Just another chapter}
Bla, bla, see appendix \ref{appendix:1}. Here should be a 1 for the first appendix and not the 2 for the last numbered chapter.


\chapter*{Appendix}

\begin{appendix}
\renewcommand{\thesection}{Anhang \arabic{section}:}
\addcontentsline{toc}{chapter}{Appendix}

\newpage
\section*{Appendix 1: Measurement X.Y.} \label{appendix:1}
\addcontentsline{toc}{section}{Appendix 1: Measurement X.Y.}
\chaptermark{Appendix}
\end{appendix}



\end{document}
  • 1
    Of course you do, how are you going to refer with a number to something without a number? But since you put a number in the title manually, i think you really should redefine your section commands in the appendix. – Johannes_B Aug 22 '14 at 8:53
  • If you need help with that, provide a minimal working example (MWE) – Johannes_B Aug 22 '14 at 8:53
  • I have added an example. – user2366975 Aug 22 '14 at 9:19
3

If there is a stick to \section*, then slightly redefining the \section* command helps, but in my this case it will always add a TOC entry automatically.

I dropped the \begin{appendix}...\end{appendix} as it provides basically no advantages in my point of view.

The pagestyle can be changed at will.

\documentclass[
    paper=a4,               
    twoside=true,           
    open=right,             
    fontsize=12pt,              
    parskip,                
    headsepline,            
    cleardoublepage=empty,  
    ]{scrbook}              

%\usepackage{etoolbox}%
\usepackage{blindtext}

\usepackage{scrpage2}       
\pagestyle{scrheadings}     
\automark[section]{chapter}
\clearscrheadings           
\ihead{}                    
\chead{}                    
\ohead{\headmark}           
\ifoot{}                    
\cfoot{}                    
\clearscrplain 
\ofoot[\pagemark]{\pagemark}
\setlength{\headheight}{1.1\baselineskip}

\usepackage[latin1]{inputenc}

\usepackage[
    backend=bibtex,
    ]{biblatex}

\usepackage[pdftex,
            colorlinks,
            linkcolor = black]{hyperref}

\usepackage[titletoc,title]{appendix} 

\newcounter{starredsection}[chapter]


\makeatletter
\let\LaTeXStandardsection\section
\newcommand{\unstarred@@section@@noopt}[1]{%
  \unstarred@@section@@opt[#1]{#1}%
}%

\newcommand{\unstarred@@section@@opt}[2][]{%
  \LaTeXStandardsection[#1]{#2}%
}%

\newcommand{\unstarredsection}{%
\@ifnextchar[{\unstarred@@section@@opt}{\unstarred@@section@@noopt}%
}%

\newcommand{\starredsection}[1]{%
\refstepcounter{starredsection}%
\LaTeXStandardsection*{#1}%
\addcontentsline{toc}{section}{\protect\numberline{}#1}%
}%

\renewcommand{\section}{%
\@ifstar{\starredsection}{\unstarredsection}%
}%




\begin{document}

\tableofcontents    

\chapter{Just a chapter}
Blabla
\chapter{Just another chapter}
Bla, bla, see appendix \ref{appendix:1}. Here should be a 1 for the first appendix and not the 2 for the last numbered chapter. But here will be 2 because, it's a reference to appendix \ref{appendix:2}%


\pagestyle{plain}
\clearscrheadings
\clearscrplain
\pagestyle{scrheadings}%
\lehead{\appendixname~\thestarredsection}

\chapter*{\appendixname}


%\begin{appendix}
%\chaptermark{Appendix}
\renewcommand{\thesection}{Anhang \arabic{section}:}
\addcontentsline{toc}{chapter}{Appendix}

%\newpage
\section*{Appendix 1: Measurement X.Y.} \label{appendix:1}
%\addcontentsline{toc}{section}{Appendix 1: Measurement X.Y.}
%\end{appendix}

\blindtext

\section*{Appendix 2: Measurement Y.Z } \label{appendix:2}

\blindtext[2]


\end{document}
  • It works, thank you. Is there a tool for writing that code, or where do the % at the end of each row come from? I am curious how I could learn such coding. – user2366975 Aug 22 '14 at 11:41
  • If there is a tool, I don't know of it and the % at the end prevents spurious white space after a command row etc. ended (or within some argument to a command). – user31729 Aug 22 '14 at 11:42
  • So it looks like I'd have to deeply dive into the manuals to be able to write such code on my own. Thank you :) – user2366975 Aug 22 '14 at 11:46
  • @user2366975: Not necessarily: I can readily explain it to you, but to be honest, I have not written such code one year before ;-) – user31729 Aug 22 '14 at 11:48
3

You should use \section and not \section*. Here's a possible solution, which assumes you don't have \subsection commands in the appendices. If you have, it is not difficult, just a little more complicated, to arrange for them.

\documentclass[
  paper=a4,               
  twoside=true,           
  open=right,             
  fontsize=12pt,              
  parskip,                
  headsepline,            
  cleardoublepage=empty,  
]{scrbook}              

\usepackage{scrpage2}       
\pagestyle{scrheadings}     
\automark[section]{chapter}
\clearscrheadings           
\ihead{}                    
\chead{}                    
\ohead{\headmark}           
\ifoot{}                    
\cfoot{}                    
\clearscrplain 
\ofoot[\pagemark]{\pagemark}
\setlength{\headheight}{1.1\baselineskip}

\usepackage[latin1]{inputenc}

\usepackage[
  backend=bibtex,
]{biblatex}

\usepackage[
  colorlinks,
  linkcolor = black
]{hyperref}

\usepackage[titletoc,title]{appendix} 

\begin{document}

\tableofcontents    

\chapter{Just a chapter}
Blabla

\chapter{Just another chapter}

Bla, bla, see appendix \ref{appendix:1}. Here should be a 1 for the first appendix 
and not the 2 for the last numbered chapter.


\chapter*{Appendix}
\addcontentsline{toc}{chapter}{Appendix}
\chaptermark{Appendix}
\renewcommand{\thesection}{\arabic{section}}

\begin{appendix}
\makeatletter
\renewcommand{\@seccntformat}[1]{Appendix \csname the#1\endcsname: }
\makeatother

\section{Measurement X.Y.} \label{appendix:1}

\end{appendix}

\end{document}

The reference

enter image description here

The appendix

enter image description here

2

If think this is the wrong way to go. Your different appenices are supposed to have the same level as the rest of the document, that is chapter. So the cleanest solution would be to use part to denote your appendix (if you really want to do so). As the numbering scheme changes from arabic to Alph the reader expects something to happen there. No need for a big hey, look everybody, the appendix starts here.

Have a look at the two solutions below, they don't require any funmbling around.

After all, this is more a question of style than the LaTeX implementation.

\documentclass{scrbook}
\begin{document}
\tableofcontents
\chapter{Polishing eggs}
See appendix \ref{app:measurement} for further information.
Especially \ref{app:measurement:xy}
\appendix
%\addcontentsline{toc}{part}{\appendixname}%
%This would be the clean solution
\chapter{Measurements}
\label{app:measurement}
\section{LASER things}
\label{app:measurement:xy}
\section{Plasma stuff}
\chapter{Third party data}
\end{document}

And here is the output for the table of contents: enter image description here

Another solution, but not as clean as the one before. But still, here we go:

\documentclass{scrbook}
\begin{document}
\tableofcontents
\chapter{Polishing eggs}
See appendix \ref{app:measurement:xy} for further information.
\appendix
\addchap{Appendix}
\renewcommand{\thesection}{\arabic{section}}
\section{Measurement LASER things} 
\label{app:measurement:xy}
\section{Measurement Plasma stuff}
\end{document}

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.