以下代码来自 egreg 的回答将阿拉伯文章节编号置于对齐的标题文本上方
\documentclass{book}
\usepackage{titlesec}
\titleformat{\section}[display]
{\sffamily\Large\bfseries}
{\filcenter\thesection}
{1.25ex}
{\justifycenter}
\newcommand{\justifycenter}[1]{%
\leftskip=0pt plus 1fil
\rightskip=0pt plus -1fil
\parfillskip=0pt plus 2fil
#1%
}
\renewcommand{\thesection}{\arabic{section}}
\begin{document}
\large
\thispagestyle{empty}
\tableofcontents
\vspace*{25pt}
\section{Here is a Section Title on Which Centers the Number Above the Title Text and Justifies the Text as Well. However, I Do Not Want the Section Entry to be Entered into the TOC Automatically. How May I Turn It Off?}
\addcontentsline{toc}{section}{1. }
\end{document}
输出结果如下:
据我所知,titlesec
会自动在目录中生成一个章节条目。
问题:我怎样才能关闭此功能,以便手动生成此类条目,例如\addcontentsline{toc}{section}{1. }
?我用编译代码lualatex
。
谢谢。
答案1
手动操作几乎总是一个坏主意。而分段命令提供了内置方法来区分目录中的内容和章节标题本身的内容。具体来说,您可以使用分段命令的可选参数来指定目录条目的形式。
通常,这用于缩短非常长的目录条目,但每当您需要区分大小写时都可以使用它。在您的例子中,您希望允许\break
在长节标题内使用,但您不希望它在目录中,因此您可以将相同的文本添加到\break
可选参数中,而无需使用\section
。
在您的示例中,我添加了(位置很糟糕)\break
来展示其工作原理。
\documentclass{book}
\usepackage{titlesec}
\titleformat{\section}[display]
{\sffamily\Large\bfseries}
{\filcenter\thesection}
{1.25ex}
{\justifycenter}
\newcommand{\justifycenter}[1]{%
\leftskip=0pt plus 1fil
\rightskip=0pt plus -1fil
\parfillskip=0pt plus 2fil
#1%
}
\renewcommand{\thesection}{\arabic{section}}
\begin{document}
\large
\thispagestyle{empty}
\tableofcontents
\vspace*{25pt}
\section[Here is a Section Title on Which Centers the Number Above the Title Text and Justifies the Text as Well. However, I Do Not Want the Section Entry to be Entered into the TOC Automatically. How May I Turn It Off?]{Here is a Section Title on Which Centers the Number Above the Title Text and\break Justifies the Text as Well. However, I Do Not Want the Section Entry to be Entered into the TOC Automatically. How May I Turn It Off?}
\end{document}