我是 LaTeX 新手,正在尝试制作一个有要求的文档。在这里和整个互联网上搜索类似问题都没有找到结果。关键是删除目录中长章节名称的第二行(第三行、第四行……)缩进。
我现在有的是:
我想要的是:
详细解释:
LaTeX 代码(MWE):
\RequirePackage[l2tabu]{nag}
\documentclass[a4paper,14pt,twoside,openany]{memoir} % Using memoir class is essential
\setcounter{tocdepth}{2} % Table of Contents depth up to 2nd level
\setrmarg{2.55em plus1fil} % No hyphenation within the Table of Contents
\begin{document}
\renewcommand{\cftchapterdotsep}{\cftdotsep} % Enable dots for Chapter instances within the Table of Contents
\renewcommand{\contentsname}{Table of Contents}
\newcommand{\acronymsname}{This is a long, really long name for acronyms list to (no-hyphenation) show how it looks within the Table of Long Contents}
\newcommand{\introductionname}{Introduction}
\tableofcontents
\chapter*{\acronymsname}
\addcontentsline{toc}{chapter}{\acronymsname}
\begin{itemize}
\item[\(E\)] --- E-letter
\item[\(j\)] --- j-letter
\item[\(k\)] --- k-letter
\end{itemize}
\chapter*{\introductionname}
\addcontentsline{toc}{chapter}{\introductionname}
Introduction text.
\chapter{First Chapter}
First Chapter text.
\section{Section One in the 1st Chapter}
...Some text...
\subsection{Subsection N1 within 1.1}
...New text...
\subsection{Subsection N2 within 1.1}
...Other text...
\section{Section Two in the 1st Chapter}
...More text...
\chapter{Second Chapter --- This Chapter Name is Really Long Too as Well as Acronyms List so it May Take at Least Two Strings}
Second Chapter text.
\section{Section One in the 2nd Chapter}
...Some text...
\section{Section Two in the 2nd Chapter}
...More text...
\end{document}
附言 这篇文章是以下文章的改进版: ...latex.org..., ...stackoverflow.com...
这些链接上有一些答案可能对你有用。但这些答案并不完全符合我在此处描述的要求。
谢谢你!
答案1
如果你有点狡猾,这是可以做到的。基本上,我们会复制两份用于在目录中排版章节条目的宏。我们修改其中一个,然后添加并使用钩子将其插入目录数据中,以更改何时使用哪个格式化宏。
\documentclass[a4paper,14pt,twoside,openany]{memoir} % Using memoir class is essential
\setrmarg{2.55em plus1fil} % No hyphenation within the Table of Contents
\setlength\cftchapterindent{0pt}
\usepackage{etoolbox}
\makeatletter
\let\normal@l@chapapp\l@chapapp
\let\special@l@chapapp\l@chapapp
\patchcmd{\special@l@chapapp}{\advance\memRTLleftskip\@tempdima}{}{\typeout{patch
ok}}{\typeout{patch failed}}
\cftinsertcode{toc-frontmatter}{\let\l@chapapp\special@l@chapapp}
\cftinsertcode{toc-mainmatter}{\let\l@chapapp\normal@l@chapapp}
\makeatother
%\documentclass{book}
\newcommand{\longname}{This is a long, really long name for acronyms
list to (no-hyphenation) show how it looks within the Table of Long
Contents}
\begin{document}
\cftinserthook{toc}{toc-frontmatter}
\frontmatter
\tableofcontents*
\chapter{\longname}
\cftinserthook{toc}{toc-mainmatter}
\mainmatter
\chapter{\longname}
\end{document}
答案2
@daleif的答案几乎涵盖了我的所有要求。但不是全部。所以我想发布我自己的结果,它使用@daleif解决方案作为基础。我只是添加了一些代码来满足所有要求。可能对某些人有帮助。代码中包含注释。
\documentclass[a4paper,14pt,twoside,openany]{memoir} % Using memoir class is essential
\usepackage{etoolbox} % Make macro writing/modifying possible
\makeatletter
\let\normal@l@chapapp\l@chapapp % Normal chapter instance in toc
\let\special@l@chapapp\l@chapapp % Special (without indent) chapter instance in toc
\patchcmd{\special@l@chapapp}{\advance\memRTLleftskip\@tempdima} % Remove indent for Special chapter instance in toc
{}
{\typeout{patch ok}}
{\typeout{patch failed}}
\cftinsertcode{toc-front-back-matter}{\let\l@chapapp\special@l@chapapp} % Hook switcing to Special (without indent) chapter instance in toc
\cftinsertcode{toc-main-matter}{\let\l@chapapp\normal@l@chapapp} % Hook switcing to Normal (with indent) chapter instance in toc
\makeatother
\makeatletter % According to my requirements the page numeration should be arabic through all the document (frontmatter, mainmatter, backmatter). This code enables it
\def\pagenumbering#1{%
\gdef\thepage{\csname @#1\endcsname \c@page}}
\makeatother
\newcommand{\longname}{This is a long, really long name for acronyms list to (no-hyphenation) show how it looks within the Table of Long Contents}
\renewcommand{\cftchapterdotsep}{\cftdotsep} % Enable dots for Chapter instances within the Table of Contents
\setcounter{tocdepth}{2} % Table of Contents depth up to 2nd level
\setrmarg{2.55em plus1fil} % No hyphenation within the Table of Contents
\begin{document}
\cftinserthook{toc}{toc-front-back-matter} % Hook switcing to the Special (without indent) chapter instance in toc
\frontmatter % Declare a front part or the document with the Special chapter instance and without chapter numbering
\pagenumbering{arabic} % Restart page numbering with Arabic
\tableofcontents*
\chapter{\longname}
\cftinserthook{toc}{toc-main-matter} % Hook switcing to the Normal (with indent) chapter instance in toc
\mainmatter % Declare a main part or the document with the Special chapter instance and with chapter numbering
\chapter{First Chapter}
First Chapter text.
\section{Section One in the 1st Chapter}
...Some text...
\subsection{Subsection N1 within 1.1}
...New text...
\subsection{Subsection N2 within 1.1}
...Other text...
\section{Section Two in the 1st Chapter}
...More text...
\chapter{Second Chapter --- This Chapter Name is Really Long Too as Well as Acronyms List so it May Take at Least Two Strings}
Second Chapter text.
\section{Section One in the 2nd Chapter}
...Some text...
\section{Section Two in the 2nd Chapter}
...More text...
\cftinserthook{toc}{toc-front-back-matter} % Hook switcing to the Special (without indent) chapter instance in toc
\backmatter % Declare a back part or the document with the Special chapter instance and without chapter numbering
\chapter{Last Chapter Long Name which may be a Conclusion or a List Of Appendixes}
\end{document}
附言 发布了另一个可行的解决方案这里经过巴特曼 (2022 年 2 月 18 日,星期五,上午 7:30)。