[Tex/LaTex] chapter style latex horizontal line

chaptersrulessectioningtitlesec

I want a chapter style like this:

                            1
------chapter name-------------

      text text text text tex
      t text text text text t

I have come this far:

\documentclass{book}

\usepackage{titlesec}

\newcommand*{\xdash}[1][3em]{\rule[0.5ex]{#1}{0.55pt}}

\titleformat{\chapter}[display]
{\Large}{\filleft\Huge\thechapter}{1ex}{\xdash[2em]}[]

\begin{document}

\chapter
{Introduction}

Text text text text

\end{document}

but I can not get it right. I want the horizontal line to be longer then the "normal" text and I want the line to be before and after the chapter name.

Best Answer

Her's an option using the explicit option for titlesec; the title is placed inside a varwidth environment of maximum width \textwidth; the left rule is drawn with a standard \rule command and the right rule uses \xrfill from the xhfill package. Long titles (spanning more than one line) are centered with respect to the rules:

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}
\usepackage{varwidth}
\usepackage{lipsum}

\titleformat{\chapter}[display]
  {\Large}{\filleft\thechapter}{2ex}
  {\hspace*{\dimexpr-4em-10pt\relax}%
    \advance\hsize4em\advance\hsize10pt%
    \rule[0.5ex]{4em}{1pt}\hspace{10pt}%
    \begin{varwidth}{\textwidth}\raggedright#1\end{varwidth}%
    \hspace{10pt}\xrfill[0.5ex]{1pt}%
  }

\begin{document}

\chapter{A short title}
\lipsum[4]
\chapter{A long title spanning several lines just to see the format in this case}
\lipsum[4]

\end{document}

An image of a short title:

enter image description here

An image of a long title:

enter image description here

Related Question