[Tex/LaTex] Align chapter title to the right

titlesec

I have the following code:

\usepackage[T1]{fontenc}

\usepackage{titlesec, blindtext, color}

\definecolor{gray75}{gray}{0.75}

\newcommand{\hsp}{\hspace{20pt}}

\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}

I would like to align the chapter title to the right. Any help? This is my current output:

enter image description here

Best Answer

Use the dedicated command, \filleft in the second mandatory argument of \titleformat if you want the whole set chapter number+ chapter title to be right aligned:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{titlesec, blindtext, color}

\definecolor{gray75}{gray}{0.75}

\newcommand{\hsp}{\hspace{20pt}}

\titleformat{\chapter}[hang]{\filleft\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}

    \begin{document}

    \chapter{Introdução}

\section{As Doenças Cerebrovasculares}
\blindtext

    \end{document}

enter image description here

Related Question