
내 문서의 일부 "특수" 장의 레이아웃을 수정하고 싶지만 나중에 이전에 사용한 레이아웃으로 재설정하고 싶습니다.
\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}
현재 설정을 저장하고 나중에 이를 사용하여 재설정하는 변수를 정의하려면 어떻게 해야 합니까?
답변1
그룹화하여 범위를 제한할 수 있습니다.
\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}
또한 새 설정을 저장하기 위해 새 명령을 정의한 다음 이전과 같이 그룹 내에서 이 명령을 사용할 수도 있습니다.
\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}
표준 레이아웃에 대해 유사한 명령을 정의하면 이제 명시적으로 그룹화하지 않고도 두 명령을 사용하여 스타일을 전환할 수 있습니다.
\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}