[Tex/LaTex] Right-align chapter/section/subsection header

horizontal alignmentsectioning

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.

Best Answer

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

Related Question