
이것은 질문에 대한 후속 조치입니다.여러 장의 상호 참조. 이 질문에 대한 답변에 따라 다음 매크로를 사용하고 있습니다.
\newcommand*\maybechapter[1]{%
% Tests if current chapter is equal to the chapter number of label)
\ifnum\value{chapter}=0#1\relax
% Print nothing if so
\else
% Set 'chapter' locally (=> no \setcounter) to the label chapter and
% print it in the usual format followed by a dot
{\value{chapter}=#1\relax\thechapter.}%
\fi
}
\renewcommand*\thesection{%
\protect\maybechapter{\arabic{chapter}}\arabic{section}%
}
이는 참조에 대해 예상대로 작동하지만 목차에서 섹션 번호는 이제 모두 장 번호 앞에 표시됩니다.
I The first chapter
I.1 The first section of the first chapter
하지만 나는 다음과 같은 것을 얻고 싶습니다
I The first chapter
1 The first section of the first chapter
이 결과를 얻으려면 \maybechapter를 어떻게 수정해야 합니까?
답변1
몇 가지 점에서 답변을 수정하겠습니다.
\documentclass{book}
\renewcommand*\thechapter{\Roman{chapter}}
\renewcommand*\thesection{%
\maybechapter{\arabic{chapter}}\arabic{section}%
}
% Maybe print the chapter number
\protected\def\maybechapter#1{%
% Tests if current chapter is equal to the chapter number of label)
\ifnum\value{chapter}=0#1
\else
\uppercase\expandafter{\romannumeral#1}.%
\fi
}
% Test document:
\begin{document}
\begingroup
\def\maybechapter#1{}
\tableofcontents
\endgroup
\chapter{One}
\section{S1}\label{S1}
Here's a reference to Section~\ref{S1},
one to Section~\ref{S2}, and one to
Section~\ref{S3}.
\section{S2}\label{S2}
Text
\chapter{Two}
\section{S3}\label{S3}
\end{document}
\protected\def
보장을 사용하면 \maybechapter
쓰기 작업이 확장되지 않습니다. TOC 항목은둘쓰기 작업 중 하나만으로는 \protect
충분하지 않습니다.
TOC의 경우 \maybechapter
명령을 로컬에서 비활성화하여 해당 인수를 게걸스럽게 먹습니다.