Text FormattingChapter formatting, swap chapter number and text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Joep
Posts: 1
Joined: Fri Jun 12, 2015 12:22 pm

Chapter formatting, swap chapter number and text

Post by Joep »

Dear all,

I am using Kile in Linux with a PDFLaTeX compiler to make a report. I use an altered version of the documentclass "book". The alterations are not causing any problems and are not the reason for this post.

I was wondering if it is possible to interchange the chapter label and text within the book enviroment using the titlesec package.

Code: Select all

\documentclass{book}
\usepackage[noindentafter]{titlesec}

\def\titlefont{\rmfamily}
\def\titleshape{\scshape}
\def\titlestyle{\titlefont\titleshape\bfseries}

\definecolor{cyan}{cmyk}{1,0,0,0}
\colorlet{title}{cyan}

\titleformat{\chapter}
    {\flushright\titlestyle}
    {\fontsize{96pt}{96pt}\selectfont\bfseries\thechapter}
    {0pt}
    {\Huge\color{title}}

\begin{document}
\chapter{Introduction}
\end{document}
I have an attachment to exemplify what I want. The first shows how it is constructed now and I want to swap the label and text so that I get the lower image. Does anyone know how to do this with the titlesec package? Or is there an easy alternative to get this?

Thanks in advance for the help!
Attachments
chapterformat.png
chapterformat.png (7.33 KiB) Viewed 2370 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Chapter formatting, swap chapter number and text

Post by rais »

Joep wrote: I was wondering if it is possible to interchange the chapter label and text within the book enviroment using the titlesec package.
yes, with its explicit option, you can put something after the title.

Code: Select all

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[noindentafter, explicit]{titlesec}
\usepackage{xcolor}
\usepackage{showframe}

\colorlet{title}{cyan}

\def\titlefont{\rmfamily\Huge}
\def\titleshape{\scshape}
\def\titlestyle{\titlefont\titleshape\bfseries\raggedleft\color{title}}

\titleformat{\chapter}
    {\titlestyle}
    {}
    {0pt}
    {#1~\fontsize{96pt}{96pt}\selectfont\thechapter}
\titleformat{name=\chapter, numberless}
    {\titlestyle}
    {}
    {0pt}
    {#1}

\begin{document}
\chapter{Introduction}
\end{document}
BTW: Before you can play around with color, you need to load one of the color packages, where cyan is usually predefined.
The command form of the flushright environment is \raggedleft.

KR
Rainer
Post Reply