我正在使用@cgnieder 的代码enotez:在尾注列表中列出章节或部分名称将内容分成不同的章节。
代码运行良好,但我书中的一些尾注位于附录或书的前言中。这反过来又造成了一些怪异的情况:
以下是我正在使用的一些代码:
\documentclass[11pt,openany,hidelinks]{book}
\usepackage[utf8]{inputenc}
\usepackage{import}
\usepackage{fullpage}
\usepackage{fontspec}
\usepackage{enotez}
\usepackage{afterpage}
\usepackage{xcolor}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{tabularx,graphicx}
\usepackage{imakeidx}
\usepackage{textcomp}
\usepackage{multicol}
\usepackage{multirow}
\usepackage[labelformat=empty]{caption}
\usepackage{array}
\usepackage{makecell}
\usepackage{etoolbox}
\usepackage{float}
\usepackage{hyperref}
\usepackage{changepage}
\urlstyle{rm}
\usepackage{fancyhdr}
\usepackage{url}
\usepackage{xurl}
\graphicspath{ {./images/} }
\indexsetup{othercode=\small}
\makeindex[program=makeindex,columns=2,intoc=false,options={-s index-style.ist}]
\usepackage{enumitem,amssymb}
\usepackage{titlesec}
\usepackage{totcount}
\usepackage{tocloft}
% Font Selection
\setmainfont[
BoldFont={DMSans-Bold.ttf},
ItalicFont={DMSans-Italic.ttf},
BoldItalicFont={DMSans-BoldItalic.ttf},
]{DMSans-Regular.ttf}
\setmonofont{DMMono-Light.ttf}
% Page Layout
\geometry{
footskip=35pt}
% Captions
\makeatletter
\renewenvironment{figure}%
{\renewcommand{\familydefault}{\ttdefault}\selectfont
\@float{figure}}
{\end@float}
\makeatother
\captionsetup{justification=raggedright,singlelinecheck=false, font=small,labelfont=tt}
\setlength{\abovecaptionskip}{17pt}
\setlength{\belowcaptionskip}{25pt}
% Chapter Headers
\regtotcounter{chapter}
\titleformat{\chapter}[hang]
{\raggedright\rmfamily\bfseries\fontsize{62}{56}\selectfont}
{\huge\rmfamily\mdseries
% magic number 20pt
\raisebox{20pt}{\smash{\parbox[t]{3em}{\thechapter\\/\\26}}}}
{0pt}{}
\titlespacing*{\chapter}{0pt}{50pt}{40pt}[140pt]
% Title Sizes
\titlespacing*{\chapter}{0pt}{0pt}{140pt}
\titleformat{\section}[display]
{\huge\bfseries}{}{0pt}{\fontsize{22}{28}\selectfont}
\titlespacing*{\section}{0pt}{17pt}{20pt}
\titleformat{\subsection}[display]
{\huge\bfseries}{}{0pt}{\fontsize{22}{28}\selectfont}
\titlespacing*{\subsection}{0pt}{20pt}{20pt}
% Custom Lists
\newlist{todolist}{itemize}{2}
\setlist[todolist]{label=$\square$}
\title{Solving Product}
\author{Étienne Garbugli}
% Endnotes
\let\footnote=\endnote
\setenotez{
backref,
totoc=false,
counter-format=arabic,
split=chapter,
split-title={\Large\chaptername\ <ref> – <title>},
}
\AfterEveryListSplit{\vspace*{-.5\baselineskip}}
\NewSplitTitleTag{title}{\nameref{ch:<split-level-id>}}
\usepackage{nameref}% automatically loaded if you use hyperref
\usepackage{letltxmacro}
\LetLtxMacro\origchapter\chapter
\RenewDocumentCommand\chapter{som}{%
\IfBooleanTF{#1}
{% starred chapter, no label then
\origchapter{#3}%
}
{% else add a label
\IfNoValueTF{#2}
{\origchapter{#3}}
{\origchapter[#2]{#3}}%
\expanded{\noexpand\label{ch:\arabic{chapter}}}%
}%
}
\DeclareInstance{enotez-list}{endnotes}{paragraph}
{heading=\section*{#1}, format=\small\ttfamily\raggedright\leftskip3em, number-format=\ttfamily}
% Footer
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\setlength{\headheight}{13.6pt}
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{mainfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{\leftmark \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{tocfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Table of Contents \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{preffoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Preface \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
% Redefine the plain page style
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[RO]{\footnotesize\ttfamily{\thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage}}
}
% Redefine Part page style
\fancypagestyle{s1foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 1: Idea \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{s2foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 2: Startup \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{s3foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 3: Growth \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{s4foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 4: Expansion \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{s5foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 5: Maturity \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
% Redefine Backmatter page style
\fancypagestyle{bbfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Building Blocks \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{appfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Appendices \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{notfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Notes \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{indfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Index \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}
\fancypagestyle{endfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{\thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage}}}
% List Styles
\setlist[enumerate]{itemsep=2pt,topsep=12pt}
% Indentation
\newenvironment{genind}{\begin{adjustwidth}{12mm}{}}{\end{adjustwidth}}
\newenvironment{quotlarind}{\begin{adjustwidth}{3pt}{60pt}}{\end{adjustwidth}}
\newenvironment{quotmedind}{\begin{adjustwidth}{3pt}{80pt}}{\end{adjustwidth}}
% Table of Contents Config
\newcount\cnta
\cftsetpnumwidth{0pt}
\renewcommand\cftsecpagefont {\ttfamily\global\cnta}
\renewcommand\cftsecafterpnum {%
\makebox[0pt][l]%
{\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\the\cnta}}%
}
\renewcommand{\cftpartfont}{\ttfamily\large}
\renewcommand{\cftchapfont}{\rmfamily\large\bfseries} \renewcommand{\cftdot}{}
\renewcommand{\contentsname}{Table of Contents}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{0}
\newlength\mylength
\renewcommand{\cftchappresnum}{Chapter }
\renewcommand{\cftchapaftersnum}{ – }
\newlength{\tocl}
\settowidth{\tocl}{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength{\cftchapnumwidth}{\tocl}
\renewcommand\cftchapafterpnum{\vskip7pt}
\renewcommand\cftpartafterpnum{\vskip12pt}
\setlength{\cftsecindent}{4em}
\renewcommand{\cftchappagefont}{\ttfamily}
\renewcommand{\cftpartpagefont}{\ttfamily}
\newcounter{oldtocdepth}
\newcommand{\hidefromtoc}{%
\setcounter{oldtocdepth}{\value{tocdepth}}%
\addtocontents{toc}{\protect\setcounter{tocdepth}{-10}}%
}
\newcommand{\unhidefromtoc}{%
\addtocontents{toc}{\protect\setcounter{tocdepth}{\value{oldtocdepth}}}%
}
\begin{document}
\clearpage
\section*{Preface}
\begin{quotmedind}
{\fontsize{15}{20}\selectfont
“If all you have is a hammer, everything looks like a nail.\endnote{Law of the instrument\newline \url{https://en.wikipedia.org/wiki/Law_of_the_instrument}}” \newline \par}
\noindent {\fontsize{9}{12}\selectfont \texttt{Abraham Maslow\index{Abraham Maslow} \newline Psychologist\newline\newline}
\par}
\normalfont \noindent \end{quotmedind}
Experience is a funny thing.\newline\newline
\chapter{Introduction}
\section{Hockey Stick Growth is a Lie}\index{Hockey Stick Growth}
\begin{quotmedind}
{\fontsize{15}{20}\selectfont
“Whenever you hear anybody talk about ‘growth hacks,'\index{Growth Hacks} just mentally translate it in your mind to ‘bullshit'.\endnote{Lecture 3 - Before the Startup (Paul Graham)\newline \url{https://youtu.be/ii1jcLg-eIQ?t=639}}”\newline \par}
\noindent {\fontsize{9}{12}\selectfont \texttt{Paul Graham\index{Paul Graham} \newline
Y Combinator\index{Y Combinator} Co-Founder\newline\newline}
\par}
\normalfont \noindent \end{quotmedind}
There are a lot of persistent myths in the technology industry, for example:
\printendnotes[endnotes]
\end{document}
- 我怎样才能调整代码,使序言中尾注的标题显示章节而不是第 0 章?
- 我怎样才能将附录中的尾注与上一章(结论)中的尾注分开?
以下是我用来将尾注分成章节的具体代码:
\setenotez{
backref,
totoc=false,
counter-format=arabic,
split=chapter,
split-title={\Large\chaptername\ <ref> – <title>},
}
\AfterEveryListSplit{\vspace*{-.5\baselineskip}}
\NewSplitTitleTag{title}{\nameref{ch:<split-level-id>}}
\usepackage{nameref}% automatically loaded if you use hyperref
\usepackage{letltxmacro}
\LetLtxMacro\origchapter\chapter
\RenewDocumentCommand\chapter{som}{%
\IfBooleanTF{#1}
{% starred chapter, no label then
\origchapter{#3}%
}
{% else add a label
\IfNoValueTF{#2}
{\origchapter{#3}}
{\origchapter[#2]{#3}}%
\expanded{\noexpand\label{ch:\arabic{chapter}}}%
}%
}