Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I change the alignment of a chapter/section/subsection heading? Preferably, I want this to be something I specify in the header, as this will be necessary for all headers in the document.

share|improve this question

3 Answers 3

up vote 17 down vote accepted

This can be done using the titlesec package.

Here's a compilable demonstration example:

\documentclass{book}
\usepackage{titlesec}
\newcommand*{\justifyheading}{\raggedleft}
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\justifyheading}{\chaptertitlename\ \thechapter}
  {20pt}{\Huge}
\titleformat{\section}
  {\normalfont\Large\bfseries\justifyheading}{\thesection}{1em}{}
\titleformat{\subsection}
  {\normalfont\large\bfseries\justifyheading}{\thesubsection}{1em}{}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\Blinddocument
\end{document}

Now the headings are right aligned. I defined a macro \justifyheading. If you later wish to left-justify or to center, simply define \justifyheading to be \raggedleft respctively \centering.

alt text

share|improve this answer
10  
Just for posterity, this can be done even simpler, just using the "easy setup" technique described on 2 of the titlesec manual: just add \usepackage[raggedleft]{titlesec} to the header. –  eykanal Dec 6 '10 at 19:22
    
@eykanal: Great, that option really works! –  Stefan Kottwitz Dec 6 '10 at 19:32

You could use a KOMA-Script-class and redefine \raggedsection.

\documentclass{scrbook}
\renewcommand*{\raggedsection}{\raggedleft}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\Blinddocument
\end{document}
share|improve this answer

Just for completeness -- This can also be accomplished with the sectsty package:

\usepackage{sectsty}
\allsectionsfont{\raggedleft}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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