
Ich möchte das Layout einiger "spezieller" Kapitel in meinem Dokument ändern, danach aber das Layout wiederherstellen, das ich vorher verwendet habe, d. h.
\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}
Wie kann ich Variablen definieren, die die aktuellen Einstellungen speichern und diese anschließend zum Zurücksetzen verwenden?
Antwort1
Sie können den Umfang durch Gruppieren einschränken:
\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}
Sie können auch einen neuen Befehl definieren, um Ihre neuen Einstellungen zu speichern, und diesen Befehl dann wie zuvor innerhalb einer Gruppe verwenden:
\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}
Durch die Definition eines ähnlichen Befehls für das Standardlayout können Sie nun mit den beiden Befehlen zwischen Stilen wechseln, ohne explizit gruppieren zu müssen:
\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}