2

I use the following code to change the chapter heading style

\usepackage{titlesec}

\definecolor{RoyalRed}{RGB}{157,16,45}
\titleformat{\chapter}[display]
  {\centering\normalfont\bfseries\LARGE}
  {\flushright\normalsize\color{RoyalRed}
  \MakeUppercase{\chaptertitlename}\hspace{1ex} \thechapter}{1pc}
  {{\titlerule[0pt]}\vspace{1pc}\MakeUppercase}

However I would not like to center the heading for chapters with chapter numbers that is when I use \chapter{Chapter1} instead of \chapter*{Abstract}. I want two different heading style dependent on \chapter or \chapter*.

Any help will be great.

2
  • Welcome to TeX.SX! For setting snippets of code, type it, select it and click ont the {} button. For inline code, place it between back quotes as I did in my edit.
    – egreg
    Feb 23, 2014 at 21:32
  • You can define the "numberless" chapter headings with \titleformat{name=\chapter,numberless}...
    – egreg
    Feb 23, 2014 at 21:33

1 Answer 1

2

As suggested by egreg, you can use

\titleformat{name=\chapter,numberless}[display]
  {\normalfont\bfseries\LARGE}
  {}{1pc}
  {{\titlerule[0pt]}\vspace{1pc}\MakeUppercase}

I have added some lines for \titlespacing also. Adjust the values as you like.

Full code:

\documentclass{book}
\usepackage{xcolor,showframe}    %% showframe just for demo
\usepackage{titlesec}

\definecolor{RoyalRed}{RGB}{157,16,45}
\titleformat{\chapter}[display]
  {\centering\normalfont\bfseries\LARGE}
  {\flushright\normalsize\color{RoyalRed}
  \MakeUppercase{\chaptertitlename}\hspace{1ex} \thechapter}{1pc}
  {{\titlerule[0pt]}\vspace{1pc}\MakeUppercase}

\titleformat{name=\chapter,numberless}[display]
  {\normalfont\bfseries\LARGE}
  {}{1pc}
  {{\titlerule[0pt]}\vspace{1pc}\MakeUppercase}

\titlespacing*{\chapter}{0pt}{0pt}{*30}                     %% adjust 30 as per need default is 50
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{*30}     %% adjust 30 as per need

\begin{document}
  \chapter{Some chapter with number}
  \chapter*{Un-numbered chapter}
\end{document}

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .