1

After the \section style is modified by the titlesec package, I want to return to the original style by \let and \renewcommand, but fails. Why and how to achieve this?

MWE:

\documentclass{article}
\usepackage{titlesec,xcolor}

\begin{document}
\section{Original Section Style}
\let\oldsection\section %store the original macro \section
\oldsection{Original Section Style stored}
\titleformat{\section}{\huge\color{red}}{\Roman{section}}{1em}{}
\section{New Section Style}
\let\section\oldsection % recovery of \section
\renewcommand{\thesection}{\arabic{section}}% I tried by another way
\section{I want to restore the original section style, but fails}
\end{document}

enter image description here

  • Different section styles may confuse readers however, as it breaks the coporate design somehow – user31729 Feb 16 '19 at 11:06
1

In section 9.2 of the titlesec manual, you find that the default style for \section is

\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{}

Thus you can go back and forward:

\documentclass{article}
\usepackage{titlesec,xcolor}

\newcommand{\originalsections}{%
  \titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{}%
}
\newcommand{\modifiedsections}{%
  \titleformat{\section}{\huge\color{red}}{\Roman{section}}{1em}{}%
}

\originalsections

\begin{document}

\section{Original Section Style A}
\section{Original Section Style B}

\modifiedsections

\section{New Section Style A}
\section{New Section Style B}

\originalsections

\section{Original Section Style C}

\end{document}

enter image description here

| improve this answer | |
1

The old definition of \section etc. must be captured by a \let statement

before

titlesec changes \section etc, i.e.

\let\oldsection\section
\usepackage{titlesec}

enter image description here

Here is the modified code:

\documentclass{article}

\let\oldsection\section %store the original macro \section

\usepackage{titlesec}
\usepackage{xcolor}


\begin{document}

\section{Original Section Style}
\oldsection{Original Section Style stored}
\titleformat{\section}{\huge\color{red}}{\Roman{section}}{1em}{}
\section{New Section Style}
\let\section\oldsection % recovery of \section
\renewcommand{\thesection}{\arabic{section}}% I tried by another way
\section{I want to restore the original section style, but fails}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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