Hello everybody. This is my first post on this forum. First of all, I´m very grateful to this forum, ´cause I've been able to solve most of my LaTeX problem looking at the posts where written on here.
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.
Text Formatting ⇒ Chapter and Section Style
Chapter and Section Style
Last edited by Blaze on Sun Jan 22, 2012 6:17 pm, edited 3 times in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Chapter and Section Style
With the help of the titlesec package (which is from Spain too I think) you can do pretty cool things. The usual way of typesetting material on a colored background with a specified width is to put it in a minipage and wrap that one into a \colorbox. This is neither convenient nor nice but at least it works.
I have tried to make an example that resembles what your picture looks like but there is surely much room for improvements.
As you can see, the last mandatory argument to \titleformat is somewhat special as it accepts the title material as its argument which I have used for the above code. However, if it is not a command that takes an argument, it is also okay.
Best
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
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
Re: Chapter and Section Style
Just, simply and obsolutely perfect 5gon12eder. I need to look the minipage environment slowly for understanding, and look for what I can change with this package. But, anyway, that´s exactly what I was looking for.
Thanks.
Blaze.
Thanks.
Blaze.