Abschnittsnummerierung in neu definierten Abschnitten

Abschnittsnummerierung in neu definierten Abschnitten

Bei der Neudefinition von Abschnitten etc. stimmt die Nummerierung in der Referenz nicht mehr.

Mein MWE ist:

\documentclass[twoside]{book}

% possibility to have sections etc. be within the margins
\makeatletter
\newcommand{\doxysection}{\@ifstar{\doxysection@star}{\doxysection@nostar}}
\newcommand{\doxysection@star}[1]{\begingroup\sloppy\raggedright\section*{#1}\endgroup}
\newcommand{\doxysection@nostar}[1]{\begingroup\sloppy\raggedright\section{#1}\endgroup}
\makeatother
\usepackage[pdftex,pagebackref=true]{hyperref}

\hypersetup{ colorlinks=true, linkcolor=blue, citecolor=blue, unicode }

\begin{document}
\chapter{Special Commands}
\doxysection{Introduction}
\begin{list}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdaddtogroup}{addtogroup}}}{\ref{commands_cmdaddtogroup}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdcallgraph}{callgraph}}}{\ref{commands_cmdcallgraph}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdhidecallgraph}{hidecallgraph}}}{\ref{commands_cmdhidecallgraph}}{}
\end{list}

\hypertarget{commands_cmdaddtogroup}{}\doxysection{addtogroup}\label{commands_cmdaddtogroup}
\hypertarget{commands_cmdcallgraph}{}\section{callgraph}\label{commands_cmdcallgraph}
\hypertarget{commands_cmdhidecallgraph}{}\doxysection{hidecallgraph}\label{commands_cmdhidecallgraph}

\end{document}

Die Ausgabe, die ich erhalte, ist:

Bildbeschreibung hier eingeben

Für die Zwecke dieses Beispiels habe ich in den Abschnittsdefinitionen für den ersten Abschnitt einen neu definierten Abschnitt, für den Abschnittsabschnitt einen Originalabschnitt und für den dritten Abschnitt wiederum einen neu definierten Abschnitt verwendet.

Hier sehen wir, dass die erste Referenz auf Abschnitt 1 verweist, obwohl dies 1.2 sein sollte. Die zweite Referenz ist korrekt, aber die dritte Referenz ist wieder falsch, dies sollte 1.4 und nicht 1.3 sein.

Es sieht so aus, als ob durch die Neudefinition des Abschnitts eine „Nummerierung“ nicht in den neuen Befehl importiert/aktualisiert wird.

(Der Tex-Code ist ein Auszug aus normalerweise automatisch generiertem Code von Doxygen.)

Wie kann ich dieses Problem lösen?

Antwort1

Sie verwenden eine Gruppierung um den Abschnittstitel und dies zerstört das \label-System, da Beschriftungsnamen lokal gespeichert werden.

Definieren Sie Ihren eigenen Abschnittsbefehl besser korrekt mit \@startsection:

\documentclass[twoside]{book}

% possibility to have sections etc. be within the margins
\makeatletter
\newcommand\doxysection{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\raggedright\normalfont\Large\bfseries}}
\makeatother
\usepackage[pagebackref=true]{hyperref}

\hypersetup{ colorlinks=true, linkcolor=blue, citecolor=blue, unicode }
\usepackage{lipsum}
\begin{document}
\chapter{Special Commands}
\doxysection{Introduction}
\begin{list}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdaddtogroup}{addtogroup}}}{\ref{commands_cmdaddtogroup}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdcallgraph}{callgraph}}}{\ref{commands_cmdcallgraph}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdhidecallgraph}{hidecallgraph}}}{\ref{commands_cmdhidecallgraph}}{}
\end{list}

\hypertarget{commands_cmdaddtogroup}{}\doxysection{addtogroup}\label{commands_cmdaddtogroup}
\hypertarget{commands_cmdcallgraph}{}\section{section}\label{commands_cmdcallgraph}
\hypertarget{commands_cmdhidecallgraph}{}\doxysection{hidecallgraph}\label{commands_cmdhidecallgraph}
\end{document} 

Bildbeschreibung hier eingeben

verwandte Informationen