1

In order to style my content, I try to color the section headings. I already have a default link color for toc. When I color my section heading, however, this format is carried to toc. I want toc to ignore that color because I color only few sections at the moment, and that section color is not suitable in toc. How do I achieve this?

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\title{ISSUE: Section formatting in TOC}


\begin{document}

\tableofcontents

\section{Introduction}

\subsection{Section 1}

asapgio pasigna psio  paiosngidpasng aoisngd apsignapgni agniaidapgip

\subsection{\textcolor{blue}{Section 2}}

asapgio pasigna psio  paiosngidpasng aoisngd apsignapgni agniaidapgip

\end{document}

Output:
enter image description here

Same example in overleaf: here

3

You can use the optional argument of \subsection to specify a different title to be displayed in the toc:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\title{ISSUE: Section formatting in TOC}


\begin{document}

\tableofcontents

\section{Introduction}

\subsection{Section 1}

asapgio pasigna psio  paiosngidpasng aoisngd apsignapgni agniaidapgip

\subsection[Section 2]{\textcolor{blue}{Section 2}}

asapgio pasigna psio  paiosngidpasng aoisngd apsignapgni agniaidapgip

\end{document}

Or (in my opinion preferable) use the colour instructions outside the \subsection macro:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\title{ISSUE: Section formatting in TOC}


\begin{document}

\tableofcontents

\section{Introduction}

\subsection{Section 1}

asapgio pasigna psio  paiosngidpasng aoisngd apsignapgni agniaidapgip

{
\color{blue}
\subsection{Section 2}
}

asapgio pasigna psio  paiosngidpasng aoisngd apsignapgni agniaidapgip

\end{document}
1

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.