[Tex/LaTex] Configuring the section with \renewcommand in the appendix won’t work

appendicesnumberingsectioning

My appendix consits of a chapter which tells the TOC that an appendix exists. All other headings in my appendix are sections.

Now I want that a section header looks like:

Appendix A. Some Text

Appendix B. Some Text

Appendix C. Some Text

But the following line

\renewcommand{\thesection}{\Alph{section}}

which can be found on most of the appendix articles won't work.

My minimal example looks like the following:

\documentclass[a4paper,12pt,headsepline,smallheadings,parident, numbers=noenddot, appendixprefix=true]{scrreprt}
\usepackage{appendix}
...

\begin{document}
\chapter{Chapter1}
\section{Section1}
\section{Section2}

%Appendix
\appendix
\renewcommand\thesection{\appendixname\ \Alph{section}}
\pagestyle{empty}

%for linking the appendix to toc without pagenumber
\phantomsection
\hypertarget{link.appendix}{}
\addchap*{Anhang}
\addtocontents{toc}{\protect\usekomafont{chapterentry}%
  \protect\hyperlink{link.appendix}{Anhang}}

\refstepcounter{chapter}
\newpage

%other try ...
%\renewcommand{\thesection}{\Alph{section}}

\section*{Class diagram} \label{class-diagram}
\section*{List of UI-Elementen} \label{list-ui-elements}
\section*{CD}
\end{document}

Best Answer

First of all you are using the starred version of \section with a label. This version doesn't provide any anchors for the label so your labeling false. A simple example shows this behavior.

\documentclass{article} 
\begin{document} 
\section*{Class diagram} \label{class-diagram}
\ref{class-diagramm}
\end{document}

The redefinition of \thesection doesn't influence the command \section* because \section* print only formated text with a predefined skip above and below.

Nevertheless you can do the following. Use \section instead of \section*. The benefits

  • you can work with the redefinition of \thesection,
  • you can use the label and
  • you get the correct headings.

With the current settings the section will be shown up in the toc. Avoiding this you can set the counter tocdepth to zero after the command `appendix.

\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}