
Gostaria de modificar o layout de alguns capítulos "especiais" do meu documento, mas depois redefinir para o layout que usei antes, ou seja
\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}
Como posso definir variáveis que armazenam as configurações atuais e posteriormente usá-las para redefinir?
Responder1
Você pode agrupar para limitar o escopo:
\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}
Você também pode definir um novo comando para armazenar suas novas configurações e então usar este comando dentro de um grupo como antes:
\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}
Definindo um comando semelhante para o layout padrão, agora você pode alternar estilos usando os dois comandos sem precisar agrupar explicitamente:
\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}