1

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.

  • I get a rule when I compile your code titlesec 2011/12/15 v2.10.0 – touhami Aug 2 '15 at 11:03
2

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}
| improve this answer | |
  • I had tried this option too, as mentioned in the question, but it didn't give me the horizontal rule. I did, however, find out what was causing the behavior I witnessed: : after defining titleformat, I was importing another package \usepackage{sectsty}. Once I commented out that line, everything started working as expected. – Chthonic Project Aug 2 '15 at 23:20
  • @ChthonicProject Don't use both those packages but only one of them. – user11232 Aug 3 '15 at 12:32
  • that's what I ended up doing. Initially, I didn't see any conflict or incompatibility mentioned in the documentation of sectsty (maybe it is there, but I missed it somehow), so I had included both. Now, I am only using titlesec. – Chthonic Project Aug 3 '15 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.