Text Formatting ⇒ Chapter and Section Style
Chapter and Section Style
Now I have a problem with the chapter and section style that I can not solve, and I couldn't find the solution. I hope someone here could help me.
My problem comes from the style of the section and chapter, specially the section. I want to fill the background of the section part, and I have no idea how to do this. I´ll upload a part of a document where you can see what I mean. I wish someone could help me to find the codes to make this kind of section and title.
Greetings from Spain.
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
-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Chapter and Section Style
I have tried to make an example that resembles what your picture looks like but there is surely much room for improvements.
Code: Select all
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
% Only these three packages are specific to the solution:
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{calc}
\definecolor{titlecolor}{HTML}{008B72}
\newcommand{\sectioncolorbox}[1]
{%
\setlength{\fboxsep}{1ex}%
\colorbox{titlecolor}%
{%
\begin{minipage}{\linewidth-2\fboxsep}
\sffamily\Large\slshape\color{white}%
\thesection.\quad#1
\end{minipage}
}%
}
\titleformat
{\chapter}
[block]
{\sffamily\huge\slshape\color{titlecolor}}
{\chaptertitlename~\thechapter.\hfill}
{0pt}
{\MakeUppercase}
\titleformat
{\section}
[block]
{}
{}
{0pt}
{\sectioncolorbox}
[]
\titlespacing*{\chapter}{0pt}{0pt}{*8}
\titlespacing*{\section}{0pt}{*10}{*4}
\renewcommand{\thesection}{\arabic{section}}
\begin{document}
\chapter{First Chapter}
\section{First Section Therein}
\lipsum
\section{Second Section Therein}
\lipsum[4]
\chapter{Second Chapter}
\lipsum
\end{document}
Best
Re: Chapter and Section Style
Thanks.
Blaze.