[Tex/LaTex] How to change the color of ONLY Table of Contents from red to black

hyperreftable of contents

This question is very close to what I want, yet not quite.

The accepted answer offers linkcolor = black, but I do not want to hide all links.

I like my in-line figure numbers and section references in red.

How can I change the link color in the Table of Contents, and only in the Table of Contents to black?

My document goes roughly like so:

...
\usepackage[]{hyperref}
\hypersetup{colorlinks=true,}
...
\begin{document}
\tableofcontents
\chapter*{...}
\chapter{...}
...
\end{document}

Best Answer

You can change the settings locally using

{
  \hypersetup{linkcolor=black}
  \tableofcontents
}

or

{
  \hypersetup{hidelinks}
  \tableofcontents
}

enter image description here

Code:

\documentclass{report}
\usepackage{blindtext}% dummy text
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,% make the links colored
}
\begin{document}
{
  \hypersetup{linkcolor=black}
  \tableofcontents
}
\chapter{First hapter}\label{ch1}
See chapter \ref{ch2}
\chapter{Second chapter}\label{ch2}
See chapter \ref{ch1}
\end{document}

If you want to remove the links from TOC complettly, you can use option linktoc=none:

\documentclass{report}
\usepackage{blindtext}% dummy text
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,% make the links colored
    linktoc=none% <- no links in ToC
}
\begin{document}
\tableofcontents
\chapter{First hapter}\label{ch1}
See chapter \ref{ch2}
\chapter{Second chapter}\label{ch2}
See chapter \ref{ch1}
\end{document}
Related Question