[Tex/LaTex] How to save and restore chapter’s heading format

chaptersformattingreportsectioning

I am writing my thesis using a template provided by the university. It requires using the report class. To format the headings in the front matter, it uses the titlesec package and redefine the format (\titleformat, \titlespacing). However, this also changes the format of chapter headings in the main matter, which I don't like. I have tried using \newenvironment to define an environment preliminary to wrap the front matter and to only redefine the headings' format locally. However it did not work.

My questions are: is it possible to change the headings' format locally? if not, how to save the default format and restore it after the front matter?

I guess I can always redefine the format after the front matter, but I want to keep the default.

Best Answer

You can use titlesec's commands anywhere and their effect will be limited to the group, or environment, containing them. The following document works with changing of sections and chapters. For illustration, I have only demonstrated sections; uncomment the lines in the body with \chapter commands to see these working too.

\documentclass{report}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\Large\itshape}{\thesection}{1em}{}{}

\newenvironment{alttitles}{\titleformat{\chapter}[display]%
{\normalfont\huge\itshape}{\chaptertitlename\ \thechapter}{20pt}{\Huge}%
\titleformat{\section}{\normalfont\Large\scshape}{\thesection}{1em}{}{}}{}

\begin{document}

%\chapter{First chapter}
\section{A section}

\begin{alttitles}
%\chapter{Next chapter}
\section{Another section}

\end{alttitles}

\section{A last section}

\end{document}

Sample output

When trying to implement this with your own styles, I suggest you first get the titlesec commands working globally in a spearate document to help debugging. After that you can build them in to an environment, if you so wish, or simply include them in the appropriate group, e.g.

{
\titleformat{\section}{\normalfont\Large\scshape}{\thesection}{1em}{}{}
\section{A small caps section}

Text.

}