背景:你好。我读过这个问答,我以为这会回答我的问题,但我仍然感到困惑(肯定是因为我对 LaTeX 还不熟悉)。我有一个使用多列和 tocloft 的两栏目录。第二列/右列的目录条目与目录的左对齐标题在同一行(即,在页面上的同一垂直方向)开始,目录的左对齐标题从左列开始。
困难:我希望目录标题出现在所有条目之上。
原始代码:
\documentclass[english]{article}
\usepackage{babel}
\usepackage{multicol}
\usepackage{tocloft}
\usepackage{hyperref}
\title{This is my report}
\author{H.S.}
\date{May, 2023}
\begin{document}
\hypersetup{linktoc=all,
colorlinks=true,
linkcolor=blue}
\renewcommand{\contentsname}{Contents}
\renewcommand{\cftaftertoctitle}{\thispagestyle{empty}}
\renewcommand{\cftsecfont}{\LARGE\aftergroup \LARGE} % credit to @user691586
\setlength{\cftsecnumwidth}{0pt} %control left margin of entry lines 2+
\renewcommand\numberline[1]{} %new % Eliminate tocloft's auto section numbers
\makeatletter
\renewcommand{\@tocrmarg}{2.55em plus 1fil} %set right margin for toc
\makeatother
\renewcommand{\cfttoctitlefont}{
\fontsize{35pt}{35pt}\selectfont
\bfseries}
\begin{hyphenrules}{nohyphenation}
\setlength{\columnsep}{50pt}
\begin{multicols}{2}
\tableofcontents
\end{multicols}
\end{hyphenrules}
\clearpage
\section{Section One Title}
\clearpage
\section{Section Two Title, Long Enough for Multiple Lines}
\clearpage
\section{Section Three Title}
\clearpage
\section{Section Four Title}
\clearpage
\section{Section Five Title}
\clearpage
\section{Section Six Title}
\clearpage
\section{Section Seven Title}
\clearpage
\section{Section Eight Title}
\clearpage
\section{Section Nine Title}
\clearpage
\section{Section Ten Title}
\clearpage
\section{Section Eleven Title}
\clearpage
\section{Section Twelve Title}
\clearpage
\section{Section Thirteen Title, surely enough to hit two columns}
\end{document}
首次尝试修复:我尝试采用@Simon Dispa 建议的解决方案这里,但我显然误解了如何包含该解决方案,因为目录页面最终完全丢失了:
\documentclass[english]{article}
\usepackage{babel}
\usepackage{multicol}
\usepackage{tocloft}
\usepackage{hyperref}
\title{This is my report}
\author{H.S.}
\date{May, 2023}
\begin{document}
\hypersetup{linktoc=all,
colorlinks=true,
linkcolor=blue}
\renewcommand{\contentsname}{Contents}
\renewcommand{\cftaftertoctitle}{\thispagestyle{empty}}
\makeatletter
\newcommand{\twocolumntoc}{
\section*{\contentsname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\begin{multicols}{2}
\@starttoc{toc}%
\end{multicols}
\onecolumn
}
\makeatother
\clearpage
\section{Section One Title}
\clearpage
\section{Section Two Title, Long Enough for Multiple Lines}
\clearpage
\section{Section Three Title}
\clearpage
\section{Section Four Title}
\clearpage
\section{Section Five Title}
\clearpage
\section{Section Six Title}
\clearpage
\section{Section Seven Title}
\clearpage
\section{Section Eight Title}
\clearpage
\section{Section Nine Title}
\clearpage
\section{Section Ten Title}
\clearpage
\section{Section Eleven Title}
\clearpage
\section{Section Twelve Title}
\clearpage
\section{Section Thirteen Title, surely enough to hit two columns}
\end{document}
我希望能做得更好的可能的修复:我认为我可以使用 \begingroup ... \endgroup 两次来实现:(1) 一个仅包含显示目录标题的文本的组;然后在其下方,(2) 一个包含目录代码的组,其中标题被 \renewcommand{\contentsname}{} 隐藏。我猜这会起作用,但基于 @Simon Dispa 对 @Marton 的回复的存在这里,感觉应该有一个比这更清晰的答案。但也许没有,这是我最好的答案。
谢谢你!
答案1
这是基于 OP 的原创努力;但插入\tableofcontents
到里面multicols
并不明显。理想情况下,最好只是查看 LaTeX 源代码,tocloft
根本不使用,自己编写所需的多列插入,以及所有所需的各种特殊内容,例如字体选择等……人们发现添加的钩子tocloft
不是理想的手段,因为人们无法控制它们是否被硬编码为在组中扩展。最后,与其观看执行的 TeX 扩展的日志跟踪,不如只latex+ tocloft
使用latex
plus article
(或任何)类,但我将在这里继续latex+article+tocloft+multicols+whatever new package...
。
\documentclass[english]{article}
\usepackage{babel}
\usepackage{multicol}
\usepackage{tocloft}
\usepackage{hyperref}
\usepackage{color}
\hypersetup{linktoc=all,
colorlinks=true,
linkcolor=blue}
\renewcommand{\contentsname}{Contents}% This is the default
% Toc configutation via tocloft interface. Which is not best of tools
% for us here.
\renewcommand{\cftaftertoctitle}{\thispagestyle{empty}}
\renewcommand{\cftsecfont}{\LARGE\aftergroup \LARGE} % credit to @user691586
% Eliminate tocloft's auto section numbers
\setlength{\cftsecnumwidth}{0pt} %control left margin of entry lines 2+
\renewcommand\numberline[1]{} %new
\renewcommand{\cfttoctitlefont}{% <- avoid extra space token
\fontsize{35pt}{35pt}\selectfont
\bfseries}
\makeatletter
\renewcommand{\@tocrmarg}{2.55em plus 1fil} %set right margin for toc
% must get rid to some extent of tocloft handling the TOC heading
% we did not correct various potential vertical space, not that importnat
\let\@cftmaketoctitle\@empty
\makeatother
\title{This is my report}
\author{H.S.}
\date{May, 2023}
\begin{document}
\begin{hyphenrules}{nohyphenation}
\setlength{\columnsep}{50pt}% configure multicols
% attenton that [{...}] would have multicols anyhow remove the braces
% so it should be [{{...}}] but anyhow we issue \normalfont to reset
% the font size and series; \noindent avoids indentation
\begin{multicols}{2}[\noindent\cfttoctitlefont\contentsname\normalfont]
\tableofcontents
\end{multicols}
\end{hyphenrules}
\clearpage
\section{Section One Title}
\clearpage
\section{Section Two Title, Long Enough for Multiple Lines}
\clearpage
\section{Section Three Title}
\clearpage
\section{Section Four Title}
\clearpage
\section{Section Five Title}
\clearpage
\section{Section Six Title}
\clearpage
\section{Section Seven Title}
\clearpage
\section{Section Eight Title}
\clearpage
\section{Section Nine Title}
\clearpage
\section{Section Ten Title}
\clearpage
\section{Section Eleven Title}
\clearpage
\section{Section Twelve Title}
\clearpage
\section{Section Thirteen Title, surely enough to hit two columns}
\end{document}
我不确定为什么要抑制连字符,但我保留了它。
我宁愿使用一些\RaggedRight
来自的ragged2e
。