재정의된 섹션의 섹션 번호 매기기

재정의된 섹션의 섹션 번호 매기기

섹션 등을 재정의할 때 참조 번호 매기기가 더 이상 정확하지 않습니다.

내 MWE는 다음과 같습니다.

\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}

내가 얻는 결과는 다음과 같습니다.

여기에 이미지 설명을 입력하세요

이 예의 목적을 위해 첫 번째 섹션의 섹션 정의에 재정의된 섹션을 사용하고, 섹션 섹션의 경우 원래 섹션을, 세 번째 섹션의 경우 다시 재정의된 섹션을 사용했습니다.

여기서는 첫 번째 참조가 섹션 1을 참조하는 것을 볼 수 있지만 이는 1.2여야 합니다. 두 번째 참조는 정확하지만 세 번째 참조는 다시 잘못되었습니다. 이는 1.3이 아닌 1.4여야 합니다.

섹션을 재정의하면 "번호 매기기"가 새 명령 내에서 가져오거나 업데이트되지 않는 것처럼 보입니다.

(tex 코드는 doxygen에서 일반적으로 자동 생성된 코드에서 발췌한 것입니다.)

이 문제를 어떻게 해결할 수 있나요?

답변1

섹션 제목 주위에 그룹화를 사용하고 있으며 이로 인해 레이블 이름이 로컬에 저장되므로 \label 시스템이 파괴됩니다.

다음을 사용하여 자신의 단면 명령을 올바르게 정의하는 것이 좋습니다 \@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} 

여기에 이미지 설명을 입력하세요

관련 정보