我想使用完整的章节标题来表示:
- 章节标题本身(当然)
- 目录
- 页眉
但是,我希望使用短名称\nameref{}
,因为否则引用太长而无法有效地与周围的文本一起使用。 (读者找到该部分不是问题,因为这些部分是按字母顺序排列的,而短版本将是部分标题的开头。)nameref
如果提供了短标题,则使用短标题,但短标题也会出现在目录中,这是我不想要的。有没有办法让目录使用长标题,而使用短标题nameref
?或者,如果有办法为 nameref 指定一个与部分标题本身不同的标题,那么也可以。
我发现了很多关于在页眉中使用短版本和在目录中使用长版本的其他问题和提示,但没有涉及\nameref{}
。
页眉不是问题,因为我正在使用memoir
并且可以轻松地单独定义页眉(在本例中与完整标题相同)。
梅威瑟:
\documentclass[twocolumn]{memoir}
\usepackage{hyperref}
\headnameref
% headers
\copypagestyle{maudcyclo}{plain}
\createmark{section}{both}{shownumber}{\sectionname}{}
\nouppercaseheads
\makeevenhead{maudcyclo}{\oldstylenums{\thepage}}{\scshape\leftmark}{}
\makeoddhead{maudcyclo}{}{\scshape\rightmark}{\oldstylenums{\thepage}}
\makeevenfoot{maudcyclo}{}{}{}
\makeoddfoot{maudcyclo}{}{}{}
\makeevenhead{plain}{\oldstylenums{\thepage}}{\leftmark}{}
\makeoddhead{plain}{}{\rightmark}{\oldstylenums{\thepage}}
\makeevenfoot{plain}{}{}{}
\makeoddfoot{plain}{}{}{}
% don't number chapters and below
\setcounter{secnumdepth}{-1}
\pagestyle{maudcyclo} % use header style
\begin{document}
\tableofcontents
\clearpage
\section[Section One][S1]{Section One}
\label{sec1}
Here is some text for section one.
\clearpage
\section[Section Two][S2]{Section Two}
Here I will reference \nameref{sec1}.
\end{document}
上述 MWE 工作正常,除了它将S1
和放在S2
标题中,而我想要Section One
和Section Two
在那里。
答案1
\patchcmd
(从包中)两次应用etoolbox
就足够了:
\patchcmd{\H@old@sectm@m}
{\csname #1mark\endcsname{#8}}
{\csname #1mark\endcsname{#9}}
{}{}
\patchcmd{\H@old@sectm@m}
{\fi #7}
{\fi #9}
{}{}
页眉将是完整的章节标题,同时\nameref
保留其原有的功能:
并且目录条目也有长格式:
为了完整起见,这里是完整的代码:
\documentclass[twocolumn]{memoir}
\usepackage{hyperref}
\headnameref
% headers
\copypagestyle{maudcyclo}{plain}
\createmark{section}{both}{shownumber}{\sectionname}{}
\nouppercaseheads
\makeevenhead{maudcyclo}{\oldstylenums{\thepage}}{\scshape\leftmark}{}
\makeoddhead{maudcyclo}{}{\scshape\rightmark}{\oldstylenums{\thepage}}
\makeevenfoot{maudcyclo}{}{}{}
\makeoddfoot{maudcyclo}{}{}{}
\makeevenhead{plain}{\oldstylenums{\thepage}}{\leftmark}{}
\makeoddhead{plain}{}{\rightmark}{\oldstylenums{\thepage}}
\makeevenfoot{plain}{}{}{}
\makeoddfoot{plain}{}{}{}
% don't number chapters and below
\setcounter{secnumdepth}{-1}
\pagestyle{maudcyclo} % use header style
\usepackage{etoolbox}
\makeatletter
\patchcmd{\H@old@sectm@m}
{\csname #1mark\endcsname{#8}}
{\csname #1mark\endcsname{#9}}
{}{}
\patchcmd{\H@old@sectm@m}
{\fi #7}
{\fi #9}
{}{}
\makeatother
\begin{document}
\tableofcontents
\clearpage
\section[Section One][S1]{Section One (long title)}
\label{sec1}
Here is some text for section one.
\clearpage
\section[Section Two][S2]{Section Two (long title)}
Here I will reference \nameref{sec1}.
\end{document}
答案2
如果您想要专门针对的不同引用\nameref
,则使用以下宏定义一个新名称:
\makeatletter
\newcommand{\namerefname}[1]{\edef\@currentlabelname{#1}}% New \nameref name
\makeatother
这是显示其用法的示例:
\documentclass[twocolumn]{memoir}
\usepackage{hyperref}
\headnameref
% headers
\copypagestyle{maudcyclo}{plain}
\createmark{section}{both}{shownumber}{\sectionname}{}
\nouppercaseheads
\makeevenhead{maudcyclo}{\oldstylenums{\thepage}}{\scshape\leftmark}{}
\makeoddhead{maudcyclo}{}{\scshape\rightmark}{\oldstylenums{\thepage}}
\makeevenfoot{maudcyclo}{}{}{}
\makeoddfoot{maudcyclo}{}{}{}
\makeevenhead{plain}{\oldstylenums{\thepage}}{\leftmark}{}
\makeoddhead{plain}{}{\rightmark}{\oldstylenums{\thepage}}
\makeevenfoot{plain}{}{}{}
\makeoddfoot{plain}{}{}{}
% don't number chapters and below
\setcounter{secnumdepth}{-1}
\pagestyle{maudcyclo} % use header style
\makeatletter
\newcommand{\namerefname}[1]{\edef\@currentlabelname{#1}}%
\makeatother
\begin{document}
\tableofcontents
\section[Section ONE]{Section One}
\namerefname{S1}\label{sec1}
Here is some text for \nameref{sec1}.
\section[Section TWO]{Section Two}
\label{sec2}
Here is some text for \nameref{sec2}.
\end{document}