章节编号中的括号

章节编号中的括号

为了在标题编号中添加“)”,我将其包含在下面的代码中:

\titleformat
    {\section} % Section type being modified
    [block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
    {\raggedright\LARGE\bfseries} % Text formatting of the whole section, i.e. label and title
    {\thesection} % Section label (e.g. number) and its formatting
    {0pt} % Horizontal space between the section label and title
    {)   } % Code before the section title
    [] % Code after the section title

\titlespacing*{\section}{0pt}{\baselineskip}{4pt} % Spacing around section titles, the order is: left, before and after

其工作原理如下图所示:

在此处输入图片描述

不幸的是,它弄乱了目录:

在此处输入图片描述

是否有其他方法可以在标题编号上插入“)”或修复目录?

谢谢!

编辑:我正在使用 titletoc 包

答案1

您误用了 的参数\titleformat

\documentclass{article}

\usepackage{titlesec}

\titleformat{\section}[block]
  {\raggedright\LARGE\bfseries}
  {\thesection)}
  {\fontdimen2\font}% a normal space
  {}

\titlespacing*{\section}
  {0pt}
  {\baselineskip}
  {4pt}

\begin{document}

\tableofcontents

\section{List of abbreviations}

\section{Foreword}

\end{document}

在此处输入图片描述

答案2

我使用 ifthenelse 解决了该问题:

\titleformat
{\section} % Section type being modified
[block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
{\raggedright\LARGE\bfseries} % Text formatting of the whole section, i.e. label and title
{\thesection} % Section label (e.g. number) and its formatting
{0pt} % Horizontal space between the section label and title
{\ifthenelse{\equal{\thesection}{0}}{}{)  }} % Code before the section title
[] % Code after the section title

'''

相关内容