# How to save and restore chapter's heading format

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.

-
Please add a fully compilable minimal working example (MWE) that illustrates your problem. Possibly with a link to your universities template. Also sometimes definitions can be restricted by putting them inside of {} or \begingroup \endgroup, but I'm not sure if that can work for you. – canaaerus Aug 27 '12 at 16:00

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}


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.

}

-

It is not possible to change them locally. However, you can revert to the "original" ones at any place in the document, and namely inside the command \mainmatter, as shown below. The correct way to define the original titles is described in titlesec manual. At this to your document preamble:

\makeatletter
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\paragraph}[runin]
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{}
\titlespacing*{\chapter}{0pt}{50pt}{40pt}
\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlespacing*{\subparagraph}{\parindent}{3.25ex plus 1ex minus .2ex}{1em}
}
\makeatother

-