![章节编号中的括号](https://linux22.com/image/458196/%E7%AB%A0%E8%8A%82%E7%BC%96%E5%8F%B7%E4%B8%AD%E7%9A%84%E6%8B%AC%E5%8F%B7.png)
为了在标题编号中添加“)”,我将其包含在下面的代码中:
\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
'''