首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在LATEX中自定义{tocloft}包生成的目录字体大小

如何在LATEX中自定义{tocloft}包生成的目录字体大小
EN

Stack Overflow用户
提问于 2017-12-02 12:35:21
回答 1查看 19.8K关注 0票数 2

我正在使用文档类"report“和包{tocloft}。我在更改由"\tableofcontents“生成的目录中明确显示的章节、章节和子章节的字体大小时遇到问题。它实际上是采用内容的大小,因为它们存在于报告中,但我想改变目录页面的字体大小。

代码语言:javascript
复制
\documentclass{report}

\usepackage{tocloft,lipsum,pgffor}

\setcounter{tocdepth}{3}% Include up to \subsubsection in ToC

\renewcommand{\cftpartfont}{\normalfont\sffamily\bfseries}% \part font in ToC
\renewcommand{\cftchapfont}{\normalfont\large\itshape}    % \chapter font in ToC
\renewcommand{\cftsecfont}{\normalfont\slshape}           % \section font in ToC
\renewcommand{\cftsubsecfont}{\normalfont\itshape}        % \subsection font in ToC
\renewcommand{\cftsubsubsecfont}{\normalfont\small}       % \subsubsection font in ToC

\begin{document}

\tableofcontents% ToC

% Create a dummy document with multiple (5) levels of sectional units
\foreach \curpart in {\Huge First, Second, Third, Last} {
  \part{\curpart{} part}
  \foreach \curchap in {\huge First, Second, Third, Last} {
    \chapter{\curchap{} chapter} \lipsum[1]
    \foreach \cursec in {\LARGE First, Second, Third, Last} {
      \section{\cursec{} section}\lipsum[2]
      \foreach \cursubsec in {First, Second, Third, Last} {
        \subsection{\cursubsec{} subsection}\lipsum[3]
        \foreach \cursubsubsec in {First, Second, Third, Last} {
          \subsubsection{\cursubsubsec{} subsubsection}\lipsum[4]
        }% \subsubsection
      }% \subsection
    }% \section
  }% \chapter
}% \part

\end{document}

我已经在虚拟文档的章节标题中添加了\huge和\LARGE。

代码语言:javascript
复制
\foreach \curchap in {\huge First, Second, Third, Last} {
    \chapter{\curchap{} chapter} \lipsum[1]
    \foreach \cursec in {\LARGE First, Second, Third, Last} {

这样做还反映了TOC页面中该部分标题的大小更改。Before adding \huge and \LARGE inside the section heading

After

我想让TOC页面中的章节和章节标题的字体大小独立于文档中发生的事情。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-05 03:28:42

您应该避免在部分单元标题中使用字体更改,因为这些更改在默认情况下会进入ToC。对于奇怪的字体更改,我建议使用

代码语言:javascript
复制
\section[<ToC entry>]{<document entry>}

你可以在<document entry>中指定任何你想要的东西,但是让<ToC entry>保持不变的字体。有关为截面单位设置字体的更全面的方法,请使用分别为<ToC entry><document entry>提供字体设置挂钩的软件包。

使用sectstytitlesec可以轻松地更改<document entry>字体,而通常使用toclofttitletoc进行<ToC entry>更改。特定于sectsty,为截面单位X重新定义\Xfont。例如,

代码语言:javascript
复制
\renewcommand{\partfont}{\normalfont\Huge\bfseries}

将仅影响\part<document content>,保持<ToC entry>不变(并且不更改字体)。

对于ToC中的每个章节单元Xtocloft提供了\cftZfont,其中X表示(来自tocloft documentation2.3节排版条目):

  • part for titles
  • chap titles
  • sec for titles
  • subtab titles
  • subsubsec titles
  • para for \subsection titles
  • fig for titles
  • subfig for titles
  • tab titles
  • subpara for \part titles
  • subfig for \section \subsectiontitles
  • fig for \paragraph titles
  • tab for \section\subsectiontitles
  • fig for \subsubsection titles
  • subfig for \subparagraph \caption \caption \section\subsection<代码>D64for subtable \caption标题

以下是如何更改与不同截面单位关联的各种组件的示例:

代码语言:javascript
复制
\documentclass{report}

\usepackage{tocloft,lipsum,pgffor,sectsty}

\setcounter{tocdepth}{3}% Include up to \subsubsection in ToC

% Font changes to ToC content of sectional units
\renewcommand{\cftpartfont}{\normalfont\sffamily\bfseries}% \part font in ToC
\renewcommand{\cftchapfont}{\normalfont\large\itshape}    % \chapter font in ToC
\renewcommand{\cftsecfont}{\normalfont\slshape}           % \section font in ToC
\renewcommand{\cftsubsecfont}{\normalfont\itshape}        % \subsection font in ToC
\renewcommand{\cftsubsubsecfont}{\normalfont\small}       % \subsubsection font in ToC

% Font changes to document content of sectional units
\renewcommand{\partfont}{\normalfont\Huge\bfseries}
\renewcommand{\chapterfont}{\normalfont\huge\bfseries}
\renewcommand{\sectionfont}{\normalfont\LARGE\bfseries}

\begin{document}

\tableofcontents% ToC

% Create a dummy document with multiple (5) levels of sectional units
\foreach \curpart in {First, Second, Third, Last} {
  \part{\curpart{} part}
  \foreach \curchap in {First, Second, Third, Last} {
    \chapter{\curchap{} chapter} \lipsum[1]
    \foreach \cursec in {First, Second, Third, Last} {
      \section{\cursec{} section}\lipsum[2]
      \foreach \cursubsec in {First, Second, Third, Last} {
        \subsection{\cursubsec{} subsection}\lipsum[3]
        \foreach \cursubsubsec in {First, Second, Third, Last} {
          \subsubsection{\cursubsubsec{} subsubsection}\lipsum[4]
        }% \subsubsection
      }% \subsection
    }% \section
  }% \chapter
}% \part

\end{document}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47604626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档