[Tex/LaTex] Flexible rule length in titlesec

rulessectioningtitlesec

I'm trying to get a rule just after the label of a chapter. (i.e., between "chapter 1" and "This is the chapter 1 title").

So far, I've managed to do this:

\titleformat{\chapter}[display]%
{\normalfont\filcenter}%
{\scshape\Huge \chaptertitlename{} \thechapter{} \\[2.75pt] {\titlerule[1pt]} \vspace*{-1\baselineskip}}%
{15pt}%
{\LARGE\bfseries}

MWE:

\documentclass{report}

\usepackage{mathptmx} % For the drop cap
\usepackage[showframe]{geometry} %Just to show the frame
\usepackage{lettrine} %For the drop cap

%% Choose one option: titlesec or sectsty
    \usepackage{titlesec}
    \titleformat{\chapter}[display]%
    {\normalfont\filcenter}%
    {\scshape\Huge \chaptertitlename{} \thechapter{} \\[2.75pt] {\titlerule[1pt]} \vspace*{-1\baselineskip}}%
    {15pt}%
    {\LARGE\bfseries}

    %\usepackage{sectsty}
    %\chapternumberfont{\centering\sc\Huge\underline}
    %\chaptertitlefont{\centering\LARGE}

\begin{document}

\chapter{Introduction}
\label{chap:Intro}


\lettrine[lines=3]{S}{ustained} bipedal locomotion is one of the main characteristics that separates the human being from other primates.  For millennia this has marked a difference not only in the way \textit{Homo Sapiens} moves, but also has played a fundamental part in the evolution and subsequent development of human beings.
\end{document}

enter image description here

but what I want it to look like is this:

enter image description here

I found a question somewhat related: Add small line in \section title, but it has a minor inconvenient: it has a fixed length. I want the rule to be set accordingly to the label width.

I'm also aware that I could achieve Fig.1 results by using the sectsty package (that's how I got the picture in the first place), but I want to be able to edit the chapter title of my bibliography so I can set in the same format as the rest of the chapter labels in the document… and I think that is only possible with titlesec (sectsty does not deal with local definitions, only global… I think)

There is also a possibility to use both packages (sectsty to set the global options and then just use titesec for the last bibliography part, but I'm not so sure about this one).

Best Answer

You can try

\documentclass{report}

\usepackage{mathptmx} % For the drop cap
\usepackage[showframe]{geometry} %Just to show the frame
\usepackage{lettrine} %For the drop cap
\usepackage{booktabs}

%% Choose one option: titlesec or sectsty
    \usepackage{titlesec}
    \titleformat{\chapter}[display]%
    {\normalfont\filcenter}%
    {\begin{tabular}{c}\scshape\Huge \chaptertitlename{} \thechapter{} \\[1ex]\bottomrule[2pt]\end{tabular}}%
    {15pt}%
    {\LARGE\bfseries}

    %\usepackage{sectsty}
    %\chapternumberfont{\centering\sc\Huge\underline}
    %\chaptertitlefont{\centering\LARGE}

\begin{document}

\chapter{Longer Introduction}
\label{chap:Intro}


\lettrine[lines=3]{S}{ustained} bipedal locomotion is one of the main characteristics that separates the human being from other primates.  For millennia this has marked a difference not only in the way \textit{Homo Sapiens} moves, but also has played a fundamental part in the evolution and subsequent development of human beings.
\end{document}

To change the distance of the line, change [1ex] to whatever you want. you can change the width of the line, I made it [2pt], which is probably too much. Notice that I \usepackage{booktabs}.

Related Question