我正在尝试使用该类memoir
,以使文档具有以下结构:
\section{A section}
\subsection{A subsection}
\subsection{Another subsection}
\subsubsection{A subsubsection}
\subsubsection{Another subsubsection}
\subsection{Yet another subsection}
\section{Another section}
给出如下标题
1 A section
1 A section >> 1.1 A subsection
1 A section >> 1.2 Another subsection
1 A section >> 1.2 Another subsection >> 1.2.1 A subsubsection
1 A section >> 1.2 Another subsection >> 1.2.2 Another subsubsection
1 A section >> 1.3 Yet another subsection
2 Another section
为此,我在序言中指出:
\def\sectionmark#1{\markright{\thesection \hskip.25cm #1}}
\def\subsectionmark#1{\markright{\rightmark \hskip.25cm >> \hskip.25cm \thesubsection \hskip.25cm #1}}
\def\subsubsectionmark#1{\markright{\rightmark \hskip.25cm >> \hskip.25cm \thesubsubsection \hskip.25cm #1}}
这几乎可以工作,但还不够。具体来说,它将生成以下标头:
1 A section
1 A section >> 1.1 A subsection
1 A section >> 1.1 A subsection >> 1.2 Another subsection
1 A section >> 1.1 A subsection >> 1.2 Another subsection >> 1.2.1 A subsubsection
1 A section >> 1.1 A subsection >> 1.2 Another subsection >> 1.2.1 A subsubsection >> 1.2.2 Another subsection
1 A section >> 1.1 A subsection >> 1.2 Another subsection >> 1.2.1 A subsubsection >> 1.2.2 Another subsection >> 1.3. Yet another subsection
2 Another section
因为 subsectionmark 和 subsubsectionmark 命令嵌套。我该怎么做才能防止这种情况发生?
答案1
下列平均能量损失重新定义负责填充奇数(或\markright
)页的三个级别的章节标记:\sectionmark
、\subsectionmark
和\subsubsectionmark
。每个<sec>
都重新定义以将其内容捕获在 中\the<sec>mark
,从而允许它在其他地方重复使用。
\documentclass{memoir}% http://ctan.org/pkg/memoir
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\setsecnumdepth{subsubsection}% Display division numbers up to \subsubsection
\renewcommand{\thesection}{\arabic{section}}% Remove \chapter number from \section
\newcommand{\sectiondiv}{\guillemotright}%
\makeatletter
\def\sectionmark#1{%
\@setclcnt{section}{@memmarkcntra}
\advance\c@@memmarkcntra\m@ne
\xdef\thesectionmark{%
\ifnum \c@secnumdepth > \c@@memmarkcntra
\if@mainmatter%
\sectionmarksn{\thesection.~}%
\fi%
\fi%
#1%
}%
\markright{\thesectionmark}}%
\def\subsectionmark#1{%
\@setclcnt{subsection}{@memmarkcntra}
\advance\c@@memmarkcntra\m@ne
\xdef\thesubsectionmark{%
\ifnum \c@secnumdepth > \c@@memmarkcntra
\if@mainmatter%
\sectionmarksn{\thesubsection.~}%
\fi%
\fi%
#1%
}%
\markright{\thesectionmark~\sectiondiv~\thesubsectionmark}}%
\def\subsubsectionmark#1{%
\@setclcnt{subsubsection}{@memmarkcntra}
\advance\c@@memmarkcntra\m@ne
\xdef\thesubsubsectionmark{%
\ifnum \c@secnumdepth > \c@@memmarkcntra
\if@mainmatter%
\sectionmarksn{\thesubsubsection.~}%
\fi%
\fi%
#1%
}%
\markright{\thesectionmark~\sectiondiv~\thesubsectionmark~\sectiondiv~\thesubsubsectionmark}}%
\makeatother
\begin{document}
\section{A section}\lipsum[1-15]
\subsection{A subsection}\lipsum[1-15]
\subsection{Another subsection}\lipsum[1-15]
\subsubsection{A subsubsection}\lipsum[1-15]
\subsubsection{Another subsubsection}\lipsum[1-15]
\subsection{Final subsection}\lipsum[1-15]
\end{document}
对传统memoir
还引入了标题格式(删除大写格式),尽管重新插入它很容易。
字体T1
编码(通过fontenc
) 是 所必需的\guillemotright
。替代符号(通过重新定义 来设置\sectiondiv
)可能会删除此添加。
答案2
这是一个使用的解决方案titleps
包及其extramarks
选项;使用一些条件来决定是否需要使用分隔符\guillemotright
:
\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage[extramarks]{titleps}
\usepackage{lipsum}
\setcounter{secnumdepth}{4}
\settitlemarks*{section,subsection,subsubsection}
\newpagestyle{main}[\small\sffamily]{
\sethead{\textsl{\thesection\ \sectiontitle\space%
\ifnum\value{subsection}>0 \guillemotright\ \else\fi%
\thesubsection\ \subsectiontitle\space%
\ifnum\value{subsubsection}>0 \guillemotright\ \else\fi%
\thesubsubsection\ \subsubsectiontitle}}{}{}
}
\pagestyle{main}
\begin{document}
\chapter{Test}
\section{A section}
\lipsum[1-10]
\subsection{A subsection}
\lipsum[1-10]
\subsection{Another subsection}
\lipsum[1-8]
\subsubsection{A subsubsection}
\lipsum[1-10]
\subsubsection{Another subsubsection}
\lipsum[1-10]
\subsection{Yet another subsection}
\lipsum[1-10]
\section{Another section}
\lipsum[1-10]
\end{document}
页面顶部的图像显示了页眉和一些文本:
但是这种方法存在一个问题:如果使用分段命令的第二个可选参数,则标记将无法正确更新;在这种情况下,必须进行一些手动工作。