[Tex/LaTex] \titleformat (in titlesec) doesn’t show any horizontal line for chapter

chaptersrulessectioningtitlesec

I have been trying to get a simple thing working with titlesec: getting a horizontal line under each chapter. There are many tutorials, documents and questions on TeX that explain how this can be done. But … each one of those answers have given me absolutely nothing. These are the solutions I have tried:

  1. Add a rule after chapter title using titlesec
  2. Two horizontal lines above and under chapter-entry
  3. Title between lines

But in each case, the compiled pdf shows exactly what it was showing without any use of \titleformat. My current preamble uses titlesec as follows:

\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

This is just one of at least a dozen variations I have tried (including the example at the end of the titlesec documentation, including the {name=\chapter,numberless} method explained in section 3.8, but all I have to show for it is this screenshot:

enter image description here

As you can see, there is no horizontal line anywhere over, under or near the chapter "Abstract". The document is nearly empty right now. After the preamble ends, all I have is

\begin{document}
\maketitle
\chapter*{Abstract}
Lorem Ipsum etc. etc.
\end{document}

I hope I was able to provide an MWE. Please let me know what I am doing wrong here so that even the most basic example is producing no result.

Best Answer

You have defined the format for numbered chapters and using an un-numbered chapter for Abstract. Defining the format for un-numbered chapters too is needed in this case to get a rule.

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

enter image description here

I have not adjusted the spacing. Please do so using \titlespacing* The default is

\titlespacing*{\chapter} {0pt}{50pt}{40pt}

Please do it also for un-numbered chapters using

\titlespacing*{name=\chapter,numberless} {0pt}{50pt}{40pt}
Related Question