\titleformat (titlesec 内) では章の水平線が表示されません

\titleformat (titlesec 内) では章の水平線が表示されません

titlesec私は、各章の下に水平線を引くという簡単なことを試してみました。チュートリアル、ドキュメント、質問がたくさんあります。テックスどのようにすればこれが実現できるかを説明するものがいくつかあります。しかし...それらの答えのどれも全く役に立ちませんでした。私が試した解決策は次のとおりです。

  1. titlesecを使用して章タイトルの後にルールを追加する
  2. 章の見出しの上下に2本の水平線
  3. 行間のタイトル

しかし、いずれの場合も、コンパイルされた 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

これは私が試した少なくとも12のバリエーションのうちの1つにすぎません(titlesec ドキュメントセクション 3.8 で説明した方法も含まれています{name=\chapter,numberless}が、それを示すのは次のスクリーンショットだけです。

ここに画像の説明を入力してください

ご覧のとおり、「概要」の章の上、下、近くには水平線がありません。文書は今のところほとんど空です。序文が終わると、私が持っているのは

\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}

関連情報