# Styling parts of document depending on section

How can I define section styles in a cls file based on the title of or label associated with a section? I don't have control over the content of the tex file other than knowing a minimal subset of titles/labels will be used.

For example, I want the content within "toppart" to be in two columns, the font size of the content within "middle part" to be 8pt, and the content within "bottompart" to have font color red.

\documentclass{article}

\begin{document}

\section{toppart}\label{toppart} %%%%%%

This is stuff at the top.

\section{middlepart}\label{middlepart} %%%%%%

This is stuff in the middle.

\section{endpart}\label{endpart} %%%%%%

This is stuff at the end.

\end{document}



To be clear, I am guaranteed to see the lines ending in %%%%%%.

• I would use three separate commands which each call \section. OTOH, changing the number of columns is nontrivial. \twocolumn forces a page break, and multicols is ended by \end{multicols}. – John Kormylo Dec 9 '19 at 13:46
• could we for example have 3 different documents--with only the section contents--which are later input\include~d in the main document – js bibra Dec 9 '19 at 13:54
• this would help--tex.stackexchange.com/questions/105684/… – js bibra Dec 9 '19 at 15:11

I think that your best bet is to use environments. The following is an example for how you could code for your toppart section.

% secprob2.tex  SE 519788 Different setting within named sections

\documentclass{article}
\usepackage{multicol}
\usepackage{lipsum}

\newenvironment{toppart}{%
\section{toppart}\label{toppart}
\begin{multicols}{2}}%
{\end{multicols}}

\begin{document}
\section{Normal section}
\lipsum[1]

\begin{toppart}
\lipsum[1]
\end{toppart}

\section{Another regular section}

There is a section~\ref{toppart}.

\lipsum[1]

\end{document}


You could, of course, extend this so that the toppart environment enabled different section titles and labels.

I leave it up to you to devise similar environments to cater for your middlepart and endpart sections.