Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to modify the layout of some "special" chapters in my document, but afterwards reset to the layout I used before, i.e.

\documentclass{report}
\usepackage{titlesec}

\begin{document}

\chapter{Normal Chapter}
\section{Normal Section}
\subsection{Normal Subsection}

% ask for current lay out:

\titlespacing*{\chapter}{0pt}{-40pt}{10pt}
\titleformat{\chapter}{\centering\Large\bf}{}{0pt}{}{}
\titleformat{\section}{\large\bf}{}{0pt}{}
\titleformat{\subsection}{\normalsize\it}{}{0pt}{}

\chapter{Special Chapter}
\section{Special Section}
\subsection{Special Subsection}

% reset to initial lay out

\chapter{Normal Chapter Again}
\section{Normal Section Again}
\subsection{Normal Subsection Again}

\end{document}

How can I define variables that store the current settings and subsequently use them to reset?

share|improve this question
    
When I read the title I assumed you wanted to change the page geometry. Would you consider changing the title to include, 'chapter headings'? –  cmhughes Dec 4 '11 at 1:29
add comment

1 Answer 1

up vote 10 down vote accepted

You can group to limit the scope:

\documentclass{report}
\usepackage{titlesec}

\begin{document}

\chapter{Normal Chapter}
\section{Normal Section}
\subsection{Normal Subsection}

% ask for current lay out:

\begingroup
\titlespacing*{\chapter}{0pt}{-40pt}{10pt}
\titleformat{\chapter}{\centering\Large\bf}{}{0pt}{}{}
\titleformat{\section}{\large\bf}{}{0pt}{}
\titleformat{\subsection}{\normalsize\it}{}{0pt}{}

\chapter{Special Chapter}
\section{Special Section}
\subsection{Special Subsection}
\endgroup
% reset to initial lay out

\chapter{Normal Chapter Again}
\section{Normal Section Again}
\subsection{Normal Subsection Again}

\end{document}

You can aldo define a new command to store your new settings, and then use this command inside a group as before:

\documentclass{report}
\usepackage{titlesec}

\newcommand\speciallayout{
  \titlespacing*{\chapter}{0pt}{-40pt}{10pt}
  \titleformat{\chapter}{\centering\Large\bf}{}{0pt}{}{}
  \titleformat{\section}{\large\bf}{}{0pt}{}
  \titleformat{\subsection}{\normalsize\it}{}{0pt}{}
}

\begin{document}

\chapter{Normal Chapter}
\section{Normal Section}
\subsection{Normal Subsection}

% ask for current lay out:

\begingroup
\speciallayout
\chapter{Special Chapter}
\section{Special Section}
\subsection{Special Subsection}
\endgroup
% reset to initial lay out

\chapter{Normal Chapter Again}
\section{Normal Section Again}
\subsection{Normal Subsection Again}

\end{document}

Defining a similar command for the standard layout, you can now switch styles using the two commands without having to explicitly group:

\documentclass{report}
\usepackage{titlesec}

\newcommand\speciallayout{
  \titlespacing*{\chapter}{0pt}{-40pt}{10pt}
  \titleformat{\chapter}{\centering\Large\bf}{}{0pt}{}{}
  \titleformat{\section}{\large\bf}{}{0pt}{}
  \titleformat{\subsection}{\normalsize\it}{}{0pt}{}
}
\newcommand\normallayout{
\titlespacing*{\chapter}{0pt}{50pt}{40pt}
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
  {\normalfont\large\bfseries}{\thesubsection}{1em}{}
}

\begin{document}

\chapter{Normal Chapter}
\section{Normal Section}
\subsection{Normal Subsection}

\speciallayout
\chapter{Special Chapter}
\section{Special Section}
\subsection{Special Subsection}

\normallayout
\chapter{Normal Chapter Again}
\section{Normal Section Again}
\subsection{Normal Subsection Again}

\end{document}
share|improve this answer
    
Good that you provided three alternatives. But, wondering if in your second example it be better to define an environment speciallayout so that you don't accidentally use it without enclosing it within a group? –  Peter Grill Dec 3 '11 at 20:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.