目录中的第二列,带有小节和子小节的副标题

目录中的第二列,带有小节和子小节的副标题

我怎样才能在目录中实现这样的效果?

目录中的章节标题

主文档中各部分应如下所示:

主文档中的章节标题

TOC 的重要特点:

  1. 小节可以有标题(小写)、副标题(正常)和额外的信息(斜体)格式不同。(但请注意,它们不必包含所有这三个,一些小节可能只有一个标题,或者只有一个副标题和信息等。)
  2. 字幕右对齐,其他内容左对齐,间隙用点填充。
  3. (理想情况下)多行标题和副标题可以得到优雅的处理。

主文档中的部分样式:

  1. 子节的标题(小型大写)、副标题(普通)和额外的信息(斜体)。
  2. 字幕右对齐,其他内容左对齐,间隙用点填充。
  3. (理想情况下)多行标题和副标题可以得到优雅的处理。

这是我用来伪造上述图像的代码(借助 GIMP)。显然,我想要一个比手动添加点来获得正确间距更好的解决方案。

\documentclass[a4paper]{article}
\usepackage{bold-extra} % Allows simultaneous bold and small-caps

\begin{document}
\tableofcontents


\section{Introduction}
My primary concern is the Table of Contents, but ideally section headings in the main part of the document should follow a similar style, with the correct formatting for \textsc{Section Titles} and \textit{(Extra Information)}, and Subtitles appearing on a separate line beneath the main titles.

The first part of this code (almost) creates a correctly formatted Table of Contents, but the formatting is wrong in the main document. The second part of the code shows how the formatting should look in the main document.

\section{First Section}
\subsection{\textsc{First Subsection} \textit{(extra info)} . . . . . . . . . . . . . . . Subtitle}
Normal text. This subsection has a title, subtitle and extra information.

\subsection{\textsc{Second Subsection} . . . . . . . . . This subtitle is so long that \\it takes 2 lines in the TOC}
This subsection lacks any extra information.

\subsubsection{\textsc{First Subsubsection} \textit{(extra info)} . . . . . . . . Subtitle}
Some Subsections have Subsubsections. These can have titles, subtitles and extra infomation too.

\subsection{\textit{(Information)} . . . . . . . . . . . . . . . . . . . . . . . . . . . Subtitle}
This subsection lacks a title.\\[1cm]
{\Large\bfseries{1 \hspace{2mm} First Section}}\\[3mm]
{\large\bfseries{\textsc{1.1 \hspace{2mm} First Subsection} \textit{(extra information)}}}\\[2mm]
\indent \hspace{4.5mm} \textit{\large Subtitle}\\[3mm]
Normal text. This subsection has a title, subtitle and extra information.

\end{document}

PDF请在您的答案中附上输出的屏幕截图。

答案1

笔记:下面的代码忘记了

\usepackage{bold-extra} % Allows simultaneous bold and small-caps

行,因此主文档中的子节标题不是小写字母。只需将该行添加到代码中即可。(图片未更新)


为了实现这一点,必须对 LaTeX 处理目录中子部分的方式进行一些调整。主要需要做的是删除页码前面默认的点,并在其他位置插入一些点。我犹豫了

  1. 直接协议\l@subsection
  2. 去吧tocloft
  3. 跟着去etoc

选项 1 意味着重复 LaTeX 内核源代码中的硬编码长度,这不是最佳选择。不幸的是,问题没有给出所用类别的指示,如果回答者不想根据 OP 逐条提供的额外数据返回 5 次来修改答案,那么这一信息至关重要。

选项 2 允许一些更具概念性的方法,但确实需要一些技巧,因为结构不是完全可定制的:在手头的情况下,\\[-\baselineskip]\null在代码中看到的奇怪的是处理一些无法通过其他方式移除的水平粘连的技巧(还有一个\strut处理另一个问题的技巧)。

选项 3 将允许使用不带技巧的代码(例如,不需要定义布尔值并将 TOC 放在环境中以告知我们的宏它们在哪里扩展,不需要\\[-\baselineskip]\null,不需要不寻常的1\filll),但同样,因为我们将完全控制,所以我们需要知道类,它会告诉我们应该模拟什么。

用户应使用\HFCtitle, \HFCinfo\HFCsubtitle如示例中标记子部分标题数据一样。 在 之后\HFCtitle和 之前留一个空格\HFCinfo

目录中副标题末尾的点不一定与其他条目标题后的点对齐,但它们应该与其他副标题后的点对齐。要实现完美对齐是另一回事,我会选择选项 3 (埃托克) 从一开始就享有完全的控制权。

\documentclass{article}

\usepackage{tocloft}
\renewcommand\cftsubsecdotsep{\cftnodots}

\makeatletter
\newif\ifHCFintoc
\newbox\HCFbox
% subsection titles in toc as in document
\protected\def\HCFtitle #1{\textsc{#1}}
% subsection infos in toc as in document
\protected\def\HCFinfo  #1{\emph{(#1)}}
% subsection subtitles need special formatting in toc
% 
\protected\def\HCFsubtitle #1%
{%
    \ifHCFintoc
%
\allowbreak\null\nobreak
\leaders\hbox{$\m@th\mkern \cftdotsep mu\hbox{\cftdot}\mkern \cftdotsep mu$}%
\hskip\z@ \@plus \@ne filll  
% 
    \setbox\HCFbox\hbox{#1}%
      \ifdim\wd\HCFbox>.3\columnwidth
        \parbox[t]{.3\columnwidth}{#1%
                   \leaders
                   \hbox{$\m@th\mkern \cftdotsep mu\hbox{\cftdot}\mkern 
                            \cftdotsep mu$}%
                   \hskip\z@ \@plus \@ne filll \strut}%
      \else
         #1%
      \fi
\\[-\baselineskip]\null
    \else
      \\\textnormal{#1}%
    \fi
}%
\makeatother
\newenvironment{HCFintoc}{\HCFintoctrue}{}

\begin{document}

\begin{HCFintoc}
  \tableofcontents
\end{HCFintoc}

\section{First section}

\subsection{\HCFtitle{First subsection}
            \HCFinfo{some info}\HCFsubtitle{This is a very very very very very
              very very long subtitle}}
Hello

\subsection{\HCFtitle{Second subsection}
            \HCFinfo{some info}\HCFsubtitle{This is a subtitle}}
Hello

\subsection{\HCFtitle{Third subsection}
            \HCFinfo{some info}\HCFsubtitle{This is a very very very very very
              very very long subtitle}}
Hello

\section{Second section with a v e r y v e r y v e r y v e r y v e r y
v e r y v e r y v e r y v e r y v e r y
              v e r y v e r y long title}

\subsection{\HCFtitle{First subsection with a v e r y v e r y v e r y v e r y v e r y
              v e r y v e r y long title}
            \HCFinfo{some info}\HCFsubtitle{This is a very very very very very
              very very long subtitle}}
Hello

\subsection{\HCFtitle{Second subsection with a v e r y v e r y v e r y v e r y v e r y
              v e r y v e r y long title}
            \HCFinfo{some very very very very very
              very very long info}\HCFsubtitle{This is a very very very very very
              very very long subtitle}}
Hello

\end{document}

第 1 页:

引用

相关内容