
我一直在嘗試做一件簡單的事titlesec
:在每章下面畫一條水平線。有很多教學、文件和問題特克斯解釋瞭如何做到這一點。但是......這些答案中的每一個都沒有為我帶來任何好處。這些是我嘗試過的解決方案:
但在每種情況下,編譯後的 pdf 都準確地顯示了它所顯示的內容,而無需使用任何\titleformat
.我目前的序言使用titlesec
如下:
\documentclass[11pt,oneside]{book}
\usepackage{titlesec}
% Below "\section" can be replaced with "\subsection" and "\subsubsection"
% in order to customize the corresponding headings. "bch" - Bitstream
% Charter, "b" - bold.
\titleformat{\section}[hang]
{\usefont{T1}{bch}{b}{n}\selectfont}
{} % label
{0em} % horizontal separation between label and title body
{\hspace{-0.4pt}\Large \thesection\hspace{0.6em}} % before-code
[] % after-code
\titleformat
{\chapter} % command
[display] % shape
{\normalfont\huge\bfseries} % format
{\chaptertitlename\ \thechapter} % label
{20pt} % sep
{\Huge}[\vspace{2ex}\titlerule] % before-code
這只是我嘗試過的至少十幾種變體之一(包括最後的示例)標題安全文檔,包括{name=\chapter,numberless}
3.8節中解釋的方法,但我要展示的只是這個截圖:
正如您所看到的,「摘要」一章上方、下方或附近沒有任何水平線。該文件現在幾乎是空的。序言結束後,我所擁有的就是
\begin{document}
\maketitle
\chapter*{Abstract}
Lorem Ipsum etc. etc.
\end{document}
我希望我能夠提供 MWE。請讓我知道我在這裡做錯了什麼,這樣即使是最基本的例子也不會產生任何結果。
答案1
您已定義編號章節的格式並使用未編號的章節Abstract
。在這種情況下,還需要定義未編號章節的格式才能獲得規則。
\documentclass[11pt,oneside]{book}
\usepackage{titlesec}
% Below "\section" can be replaced with "\subsection" and "\subsubsection"
% in order to customize the corresponding headings. "bch" - Bitstream
% Charter, "b" - bold.
\titleformat{\section}[hang]
{\usefont{T1}{bch}{b}{n}\selectfont}
{} % label
{0em} % horizontal separation between label and title body
{\hspace{-0.4pt}\Large \thesection\hspace{0.6em}} % before-code
[] % after-code
\titleformat
{\chapter} % command
[display] % shape
{\normalfont\huge\bfseries} % format
{\chaptertitlename\ \thechapter} % label
{20pt} % sep
{\Huge}[\vspace{2ex}\titlerule] % before-code
\titleformat
{name=\chapter,numberless} % command
[display] % shape
{\normalfont\huge\bfseries} % format
{} % label
{0pt} % sep
{\Huge}[\vspace{2ex}\titlerule] % before-code %% adjust 2ex here as you want.
\begin{document}
%\maketitle
\chapter*{Abstract}
Lorem Ipsum etc. etc.
\end{document}
我沒有調整間距。請使用\titlespacing*
預設值來執行此操作
\titlespacing*{\chapter} {0pt}{50pt}{40pt}
請對未編號的章節也執行此操作
\titlespacing*{name=\chapter,numberless} {0pt}{50pt}{40pt}