回忆录:简短和详细目录的标题

回忆录:简短和详细目录的标题

以下memoirdocumentclass 源生成两个目录 - 一个简短目录和一个详细目录。(区别在于只有后者包含子节。)

问题:如何让每个页面的名称(分别为\shortcontentsname和的值\longcontentsname)出现在其第一页之后的页眉中?例如,我想看到

iv                                                   Detailed Contents

Detailed Contents                                                   v

分别表示左侧页面 iv 和右侧页面 v。

正如消息来源所示,我尝试过

\createplainmark{shorttableofcontents}{both}{\shortcontentsname}
\createplainmark{longtableofcontents}{both}{\longcontentsname}  

在 内\makepsmarks{main},但这样会生成只包含页码的页眉。我还尝试过

\createplainmark{shortttoc}{both}{\shortcontentsname}
\createplainmark{longtoc}{both}{\longcontentsname} 

\createplainmark{toc::shorttoc}{both}{\shortcontentsname}
\createplainmark{toc::longtoc}{both}{\longcontentsname}   

但结果相同。

\documentclass{memoir}

%% PAGE STYLEs
\nouppercaseheads
\makepagestyle{main} 
\makeheadrule{main}{\textwidth}{\normalrulethickness}
\makeevenhead{main}{\bfseries\sffamily\thepage}{}{\bfseries\sffamily\leftmark}
\makeoddhead{main}{\bfseries\sffamily\rightmark}{}{\bfseries\sffamily\thepage} 
\addtopsmarks{main}{}{%
  % insert "Chapter\space" & "Section\space" if desired as 4th argument:
  \createmark{chapter}{left}{shownumber}{}{\enspace} 
  \createmark{section}{right}{shownumber}{}{\enspace}
}
% daleif (https://tex.stackexchange.com/a/512636/13492):
\makepsmarks{main}{%
  \createmark{chapter}{both}{shownumber}{}{\enspace} % use both not left
  \createmark{section}{right}{shownumber}{}{\enspace}
  \createplainmark{toc}{both}{\contentsname}
  \createplainmark{lof}{both}{\listfigurename}
  \createplainmark{lot}{both}{\listtablename}
  \createplainmark{bib}{both}{\bibname}
  \createplainmark{index}{both}{\indexname}
  \createplainmark{glossary}{both}{\glossaryname}
  % ---> My attempted additions: <---
  \createplainmark{shorttableofcontents}{both}{\shortcontentsname}
  \createplainmark{longtableofcontents}{both}{\longcontentsname}  
}

\chapterstyle{default}
\pagestyle{main}

%% SECTIONING STYLES
\setsecnumdepth{subsection}

% CROSS-REFERENCING
\usepackage[pdftex]{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev]{cleveref}
\usepackage{crossreftools}

%% SHORT & LONG TOCs
%% Code by Christian Hupfer 
% Just in case we're not loading hyperref
\makeatletter
%
\@ifpackageloaded{hyperref}{%
}{
  \providecommand{\@currentHref}{}
  \providecommand{\hyperlink}[2]{#2}
  \providecommand{\getrefnumber}[1]{}
  \providecommand{\phantomsection}{}
}
\AtBeginDocument{%
  \newcommand{\shortcontentsstuff}{%
  \contentsline{chapter}{\hyperlink{\getrefnumber{toc::shorttoc::anchor}}{\shortcontentsname}}{\pageref{toc::shorttoc}}{\getrefnumber{toc::shorttoc::anchor}}
}
\newcommand{\longcontentsstuff}{%
  \contentsline{chapter}{\hyperlink{\getrefnumber{toc::longtoc::anchor}}{\longcontentsname}}{\pageref{toc::longtoc}}{\getrefnumber{toc::longtoc::anchor}}
}
}
\newif\if@shorttoc
%
\renewcommand{\tableofcontents}{%
  \if@twocolumn
  \@restonecoltrue\onecolumn
  \else
  \@restonecolfalse
  \fi
  \chapter*{\contentsname
   \@mkboth{%
     \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
 % Addition
 \if@shorttoc
 \protected@edef\@currentlabel{shorttoc}% Rather unimportant
 \edef\@currentlabelname{\shortcontentsname}% For \nameref
 \label{toc::shorttoc}% 
 % Now let us fix the hyperanchor for the short toc
 \edef\@currentlabelname{}%
 \protected@edef\@currentlabel{\@currentHref}\label{toc::shorttoc::anchor}
 \else
 \protected@edef\@currentlabel{longtoc}% Rather unimportant
 \edef\@currentlabelname{\longcontentsname}
 \label{toc::longtoc}%
 % Now let us fix the hyperanchor for the long toc
 \edef\@currentlabelname{}%
 \protected@edef\@currentlabel{\@currentHref}\label{toc::longtoc::anchor} 
 \fi
 % End of additions
 \@starttoc{toc}%
 \if@restonecol\twocolumn\fi
}
%
\newcommand{\longcontentsname}{Detailed Contents}
\newcommand{\shortcontentsname}{Short Contents}
%
\newcommand{\shorttableofcontents}[1][1]{%
  \begingroup
  \@shorttoctrue
  \setcounter{tocdepth}{#1}
  \let\shortcontentsstuff\relax
  \phantomsection
  \write\@auxout{\string\@writefile{toc}{\protect\longcontentsstuff}}
  \let\contentsname\shortcontentsname% Disabling the \shortcontentsstuff in toc
  \tableofcontents
  \endgroup
  \@shorttocfalse% Disable the short toc
}
\newcommand{\longtableofcontents}[1][3]{%
  \begingroup
  \setcounter{tocdepth}{#1}
  \phantomsection
  \let\longcontentsstuff\relax% Disabling the \longcontentsstuff in toc
  \write\@auxout{\string\@writefile{toc}{\protect\shortcontentsstuff}}
  \let\contentsname\longcontentsname
  \tableofcontents
  \endgroup
}
%
\makeatother

%% FOR THIS DEMO:
\usepackage{lipsum}

\begin{document}

\frontmatter
\shorttableofcontents\cleardoublepage
\longtableofcontents

\mainmatter
\chapter{One}
\lipsum[1]

\section{A section}
\subsection{First}
\lipsum[1-7]
% Many (sub-)sections to force multi-page TOC
\subsection{Second}
\subsection{Third}\subsection{Four}\subsection{Five}\subsection{Six}
\subsection{Seven}\subsection{Eight}\subsection{Nine}
\subsection{Ten}\subsection{Eleven}\subsection{Twelve}
\subsection{Thirteen}\subsection{Fourteen}\subsection{Fifteen}
\subsection{Sixteen}\subsection{Seventeen}\subsection{Eighteen}
\subsection{Nineteen}\subsection{Twenty}\subsection{Twenty-one}
\subsection{Twenty-two}\subsection{Twenty-three}\subsection{Twenty-four}
\subsection{Twenty-five}\subsection{Twenty-six}\subsection{Twenty-seven}
\section{B section}\section{C section}\section{D section}
\section{E section}\section{F section}\section{G section}\section{H section}
\section{I section}\section{J section}\section{K section}\section{L section}
\section{M section}\section{N section}\section{O section}\section{P section}
\section{Q section}\section{R section}\section{S section}\section{T section}
\section{U section}\section{V section}\section{W section}\section{X section}
\section{Y section}\section{Z section}\section{AA section}\section{BB section}
\section{CC section}\section{DD section}\section{EE section}\section{FF section}
\section{GG section}\section{HH section}\section{II section}\section{JJ section}
\section{KK section}\section{LL section}\section{MM section}\section{NN section}
\section{OO section}\section{PP section}\section{QQ section}\section{RR section}
\section{SS section}\section{TT section}\section{UU section}\section{VV section}
\section{WW section}\section{XX section}\section{YY section}\section{ZZ section}

\end{document}

以下是我现在获得的详细目录中的页面内容:

详细内容,偶数页页眉缺失 longcontentsname

详细内容 奇数页页眉缺失 longcontentsname

参考:

  • 这个问题是https://tex.stackexchange.com/a/512636/13492(其工作方式与其他前言和正文一致。
  • 两个目录的代码部分来自https://tex.stackexchange.com/a/346433/13492。不幸的是,这种方法不是保留pagestyle短目录和长目录中章节页之后的页面。但是,它确实会在另一个目录中生成所需的每个条目,并且只在另一个目录中生成所需的条目;并且它使每个条目上的链接指向相应目录页面的顶部。

部分解决方案:

使用该etoc包允许创建一个短目录和一个长目录,以保留页面样式和章节样式 - 但是,似乎不允许两个目录中的每一个仅为另一个目录提供一个条目。

看:memoir:从两个目录中排除其他目录的条目

答案1

这是一个更好的解决方案。这在有和没有biblatex和的情况下都有效hyperref。特别感谢 Ulrike Fischer 提供的技巧https://tex.stackexchange.com/a/513634/3929这构成了该解决方案的基础。

还添加了一个轻微的变化,memoir使得 toc 标题的锚点现在是多于标题而不是下方。这将包含在下一memoir版本中。

我没有包括你对长短目录的论点,我相信你可以自己做出这些调整。

\documentclass[a4paper]{memoir}

% this changes where the hyperref anchor for the TOC header is, will
% be in the next memoir release
\makeatletter
\renewcommand{\newlistof}[3]{%
  \@namedef{ext@#2}{#2}
  \@ifundefined{c@#2depth}{\newcounter{#2depth}}{}
  \setcounter{#2depth}{1}
  \@namedef{#2mark}{\markboth{#3}{#3}}
   \@namedef{#1}{\@ifstar{\@nameuse{mem@#1}{01}}{\@nameuse{mem@#1}{00}}}
  \@namedef{cft#2beforelisthook}{}%
  \@namedef{cft#2afterlisthook}{}%
  \@namedef{mem@#1}##1{%
    \ensureonecol
    \par
    \begingroup
      \phantomsection
      \if##1
        \ifmem@em@starred@listof\else
          \addcontentsline{toc}{chapter}{#3}
        \fi
      \fi
      \@nameuse{@#2maketitle}
      \parskip\cftparskip
      \@nameuse{cft#2beforelisthook}%
      \@starttoc{#2}%
      \@nameuse{cft#2afterlisthook}%
    \endgroup
    \restorefromonecol}
  \@namedef{@#2maketitle}{%
    \@nameuse{#2headstart}
   {\parindent\z@
    \parskip\z@
%%%%  \parskip\cftparskip
    \interlinepenalty\@M
    \@nameuse{print#2nonum}%
    \@nameuse{print#2title}{#3}%
    \@nameuse{#2mark}%
    \thispagestyle{chapter}%
    \@nameuse{after#2title}
   }
    \@afterheading}
  \@namedef{#2headstart}{\chapterheadstart}
  \@namedef{after#2title}{\afterchaptertitle}
  \@namedef{print#2nonum}{\printchapternonum}
  \@namedef{print#2title}##1{\printchaptertitle{##1}}
} % end \newlistof
\newlistof{tableofcontents}{toc}{\contentsname}

\makeatother

% just to show this woth with biblatex and hyperref
\usepackage{biblatex}
\usepackage[colorlinks]{hyperref}


\newif\ifSHORT
\newif\ifLONG

% credit for Ulrike Fischer for this idea, we need to have the
% conditionals defined **inside** the toc
\DeclareRobustCommand\activateif{%
\let\showShort\ifSHORT
\let\showLong\ifLONG
\let\stopShort\fi
\let\stopLong\fi
}

\usepackage{xpatch}


% next use patching to add a wrapper around the \addcontentsline
% that \tableofcontents generates. Since this is inside a group we
% don't having one patch messing up the other
\makeatletter
\newcommand\shortTOC{
  \begingroup
  \setcounter{tocdepth}{0}
  \def\contentsname{Short toc}
  \xpatchcmd{\mem@tableofcontents}%
  {\addcontentsline{toc}{chapter}{\contentsname}}{%
    \addtocontents{toc}{\protect\showShort}%
    \addcontentsline{toc}{chapter}{\contentsname}
    \addtocontents{toc}{\protect\stopShort}%
  }{\typeout{ok}}{\typeout{failed}}
  \LONGtrue
  \tableofcontents
  \endgroup
}

\newcommand\longTOC{
  \begingroup
  \setcounter{tocdepth}{3}
  \def\contentsname{Long toc}
  \xpatchcmd{\mem@tableofcontents}%
  {\addcontentsline{toc}{chapter}{\contentsname}}{%
    \addtocontents{toc}{\protect\showLong}%
    \addcontentsline{toc}{chapter}{\contentsname}
    \addtocontents{toc}{\protect\stopLong}%
  }{\typeout{ok}}{\typeout{failed}}
  \SHORTtrue
  \tableofcontents
  \endgroup
}

% automatically add the activation to the toc
\AtBeginDocument{
  \addtocontents{toc}{\activateif}
}

\makeatother

\usepackage{kantlipsum}
\begin{document}

\frontmatter

\shortTOC

\clearpage

\longTOC

\mainmatter

\newcommand\Sample{
\chapter{Chap}
\kant[1]
\section{Test}
\kant[1]
\subsection{Test}
\kant[1]
}

\Sample\Sample\Sample\Sample\Sample\Sample\Sample
\Sample\Sample\Sample\Sample\Sample\Sample\Sample
\Sample\Sample\Sample\Sample\Sample\Sample\Sample
\Sample\Sample\Sample\Sample\Sample\Sample\Sample


\end{document}

已删除旧的易碎解决方案

相关内容