Document Classescustom chapter and section

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
pozdrav
Posts: 3
Joined: Tue Nov 10, 2009 10:55 am

custom chapter and section

Post by pozdrav »

Hi guys,
I just stumbled upon this forum. It seems a great resource for learning latex and I am in dire need of some custom templating for *chapters* and *section*. I am not absolutely new to latex but have never worked in tweaking styles or the like.
I have uploaded the images of the format I would like to have here:
TITLE:
titlefw.jpg
titlefw.jpg (45.96 KiB) Viewed 11012 times
SECTION:
sectionl.jpg
sectionl.jpg (25 KiB) Viewed 11012 times
In the chapters, I do not need the picture in the background (parabolas). I just need *chapter 1* with the blue rectangle surrounding it, followed by the name.

Could you please suggest me how to go about?
thank you very much,
best, arun.

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

custom chapter and section

Post by gmedina »

Hi,

I would suggest you to use the titlesec package; the following code is an example that could give you some ideas to get the format for sections:

Code: Select all

\documentclass{book}
\usepackage[x11names]{xcolor}
\usepackage[explicit]{titlesec}

\titleformat{\section}[block]
  {\normalfont\sffamily}
  {\colorbox{blue!70}{\parbox[c][15pt][c]{30pt}{%
      \hfil\color{white}\Large\thesection\hfil}}}
  {0pt}
  {\parbox{\linewidth}{%
      \hspace*{1em}\color{DeepSkyBlue2}\large\sffamily#1\\[-8pt]\color{DeepSkyBlue2}\titlerule}}
\titlespacing*{\section}
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\begin{document}

\chapter{Test chapter}
\section{Test section}

\end{document}


For chapter titles you could additionally use the PGF/TikZ package. Following the link below you will find an example thet could help you to get started:

Fancy chapter headings with TikZ - TeXblog.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
pozdrav
Posts: 3
Joined: Tue Nov 10, 2009 10:55 am

custom chapter and section

Post by pozdrav »

Hi gmedina,
Thank you very much. It works like a charm. I have just one question. How can I increase the thickness of the line?

In addition, I tried out the code for *chapter*, its about 70-80% as I intend to be...

Code: Select all

\titleformat{\chapter}[block] 
    {\begin{picture}(330,200)} {%
	\put(0,230){% 
	   \makebox(0,0)[lb]{%
		\colorbox[named]{Cerulean}{%
	   	    \begin{tabular}{c}%
			\multirow{3}{*}{}%
		   	      \textit{\textcolor{white}{Chapter}}\\%
			      \\%
			      \Huge \textcolor{white}{\thechapter}%
		    \end{tabular}
		    }
	    }
	}
	\textcolor[named]{Cerulean}{\uppercase{%
		\put(75,250){%
			\parbox[t]{300pt}{% 
				\LARGE\filright #1
			}
		}
	}}
    } 
	   {0pt}{}
	   [\end{picture}]

I have attached the output as a .jpg file here.

I was not able to figure out is how to change the font of the numbers below *chapter* even bigger.. Its already \Huge. Also, I would like the first letter to be bigger caps than the others (in word, this option is Small caps). I don't want to just increase the size of I to make the others look smaller.. I wonder if an option is there in latex to accomplish this?

Other than that, I think this looks good. Except, I wonder if the \parbox will disrupt the alignment with Chapter if the name of the chapter is too long...

I would appreciate if you have any suggestions in this regard, or any other suggestions.

Also, I noted that your code for \section changes the font and also draws a line for *Abstract* and *Acknowledgements* section of my thesis.
I would like to know how I could remove them (in case I don't want these options there) and also if/how to add similarly to reflect in Header, footer, table of contents etc...

I hope your code could be easily replaced for subsection too. If so, I don't have a problem there.

Thank you very much for your help. I would appreciate if you could give some pointers to my questions.

very best,
Arun.
Attachments
Chapter - Latex code
Chapter - Latex code
chp1.jpg (17.91 KiB) Viewed 10981 times
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

custom chapter and section

Post by gmedina »

Hi, Arun
pozdrav wrote:...Also, I noted that your code for \section changes the font and also draws a line for *Abstract* and *Acknowledgements* section of my thesis.
I would like to know how I could remove them (in case I don't want these options there)...
You can use \titleformat and \titlespacing* as many times as you wish inside the body of your document to change the format. Have a look at the following example, that switches between the fancy and the standard format (as defined for the book document class) for sections:

Code: Select all

\documentclass{book}
\usepackage[x11names]{xcolor}
\usepackage[explicit]{titlesec}

\titleformat{\section}[block]
  {\normalfont\sffamily}
  {\colorbox{blue!70}{\parbox[c][15pt][c]{30pt}{%
      \hfil\color{white}\Large\thesection\hfil}}}
  {0pt}
  {\parbox{\linewidth}{%
      \hspace*{1em}\color{DeepSkyBlue2}\large\sffamily#1\\[-8pt]\color{DeepSkyBlue2}\titlerule}}
\titlespacing*{\section}
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\begin{document}

\chapter{Test chapter}

\section{Test section with a fancy title}

\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection\ #1}{1em}{}
\titlespacing*{\section} 
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\section{Test section with a normal title}

\titleformat{\section}[block]
  {\normalfont\sffamily}
  {\colorbox{blue!70}{\parbox[c][15pt][c]{30pt}{%
      \hfil\color{white}\Large\thesection\hfil}}}
  {0pt}
  {\parbox{\linewidth}{%
      \hspace*{1em}\color{DeepSkyBlue2}\large\sffamily#1\\[-8pt]\color{DeepSkyBlue2}\titlerule}}
\titlespacing*{\section}
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\section{Another test section with a fancy title}

\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection\ #1}{1em}{}
\titlespacing*{\section} 
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\section{Another test section with a normal title}

\end{document}
pozdrav wrote:...I was not able to figure out is how to change the font of the numbers below *chapter* even bigger.. Its already \Huge...
Using the \fontsize command you can increase the font size:

Code: Select all

\documentclass{book}
\usepackage{fix-cm}

\begin{document}

text text {\fontsize{40}{48}\selectfont text text} text text

\end{document}
Using \scshape you can change the font shape to small capitals:

Code: Select all

\documentclass{book}

\begin{document}

text text {\scshape Text text} text text

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
pozdrav
Posts: 3
Joined: Tue Nov 10, 2009 10:55 am

Re: custom chapter and section

Post by pozdrav »

Thank you very much!

I guess I have fixed everything I have in mind now. In case I run into any other problems, I will post again :)

I was able to fix the linewidth under section by just using \titlerule[1pt]

best, Arun.
Post Reply