# chapter style latex horizontal line

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.

• When you say "longer" do you mean all the page should be crossed by the line or only some cm on each side? – Ludovic C. Aug 7 '13 at 17:07

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

An image of a long title:

• Perfect. Shorter code and easier to follow! How to i do if i want say my abstract page to have this kind of style also? I copied your code and changed from Chapter to Section, but of course these changes every section in my document. Can i use different settings for the section in different part of the document or how to i solve this in an easy way? – Mike Aug 7 '13 at 18:19
• @Mike hard to say if you don't provide precise information on the structure of your document. How are you producing your abstracta? Is your abstract a section produced with \section*? – Gonzalo Medina Aug 7 '13 at 18:23
• I am using for my abstract \begin{abstract}, begin{notation} for notation page, \tableofcontents for table of content page. These pages i would like a similar style like the chapters. The sections in the different chapters will i probably want to use some ordinary style. Hope that helps with explaining my document. – Mike Aug 7 '13 at 18:33
• @Mike no, it doesn't help much. In your question you mentioned the book document class, and this class doesn't provide an abstract environment nor a notation environment. You can use different styles for sections in your document, but I need to know the exact structure used to give you the most effective alternative. – Gonzalo Medina Aug 7 '13 at 18:42
• The problem is that i am using a class made by my university. – Mike Aug 7 '13 at 18:47