2

I would like to use the hypperref to create blue links for only toc sections and subsections.

\documentclass[12pt,oneside]{book}
\usepackage{amsmath,amssymb,amsthm,amstext,amscd,amsfonts,amsbsy,amsxtra,latexsym,cite,hyperref}
\usepackage[retainorgcmds]{IEEEtrantools}
\usepackage{ytableau}
\usepackage{titlesec}
\usepackage{mathrsfs}
\usepackage{verbatim}                 % math stuff                 % more math stuff
\usepackage{graphicx}                % including figures
\usepackage[lofdepth]{subfig}        % subfigures
\usepackage[left=1.0in,right=1.0in,%
 top=1.0in,bottom=1.0in]{geometry}  % margin control
\usepackage[toc,page]{appendix}      % appendix stuff
\usepackage{times}                   % Times New Roman font
\usepackage{color}                   % colored text
\usepackage{float}
\usepackage[square, numbers]{natbib} % nicer citing
\usepackage{indentfirst}             % indents first paragraph of every section
\usepackage{setspace}                % manual line spacing control
\usepackage{fancyhdr}                % these 5 lines are for header/footer:
\fancypagestyle{plain}{
\fancyhead[R]{\thepage}\fancyhead[L]{}\fancyfoot[C]{}
\renewcommand{\headrulewidth}{0pt}}
\pagestyle{plain}
\setlength{\headheight}{15pt}
\usepackage{titlesec}                % these 4 lines are for formatting chapter titles:
\titleformat{\chapter}[display]
{\normalfont\Huge\bfseries\centering}
{\vspace{8ex}\chaptertitlename\ \thechapter}{20pt}{\Huge}
\renewcommand{\headrulewidth}{0pt}}
\pagestyle{plain}
\setlength{\headheight}{15pt}
\usepackage{titlesec}                % these 4 lines are for formatting chapter titles:
\titleformat{\chapter}[display]
{\normalfont\Huge\bfseries\centering}
{\vspace{8ex}\chaptertitlename\ \thechapter}{20pt}{\Huge} 

\hypersetup{
    colorlinks=true, % make the links colored
    linkcolor=blue, % color TOC links in blue
    linktoc=all % 'all' will create links for everything in the TOC
}  

After some more stuff, I start my document, which minimally looks like this:

\begin{document}
    \renewcommand{\contentsname}{Table of Contents}
    \tableofcontents

    \mainmatter
    \include{mainmatter/chapter1/chapter1}
    \include{mainmatter/chapter2/chapter2} 

    \backmatter
    \include{backmatter/bibliography}

\end{document}

The mainmatter sections are where the problem arises; all equation labels are colored blue, and references (e.g. "[21]") are colored green. Nowhere did I even specify green to be a color, and in the hyppersetup fragment above I specified to create links only for the toc, and not for labels/references within the document.

I didn't include specific matter I had in the main sections because I didn't think it was relevant. Please let me know if I should add any should it help.

1
  • 3
    Make a small example that one can compile and that demonstrates the problem. Don't use \include in such an example -- we don't have the files. Remove irrelevant packages. Commented Mar 19, 2016 at 16:16

1 Answer 1

5

If the document starts with the TOC you can use \hypersetup{hidelinks} after the table of contents is finished.

\documentclass{book}
\usepackage{blindtext}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true, % make the links colored
    linkcolor=blue, % color TOC links in blue
    linktoc=all % 'all' will create links for everything in the TOC
}
\begin{document}
\tableofcontents
\hypersetup{hidelinks}
\chapter{First hapter}\label{ch1}
See chapter \ref{ch2}
\chapter{Second chapter}\label{ch2}
See chapter \ref{ch1}
\end{document}

Or you change all colors to black globally and set linkcolor=blue for the TOC locally.

\documentclass{book}
\usepackage{blindtext}
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true, % make the links colored
    linkcolor=black, % color TOC links in blue
    citecolor=black,
    filecolor=black,
    urlcolor=black,
    linktoc=all % 'all' will create links for everything in the TOC
}
\begin{document}
{
  \hypersetup{linkcolor=blue}
  \tableofcontents
}
\chapter{First hapter}\label{ch1}
See chapter \ref{ch2}
\chapter{Second chapter}\label{ch2}
See chapter \ref{ch1}
\end{document}
2
  • That works, thanks. But its not really a fix, given that the labels and references are still links. Is this something we have to live with?
    – user101099
    Commented Mar 19, 2016 at 22:49
  • I think you have to live with. Or you use the starred versions \ref*{...} and \pageref*{...} to get references that are not links.
    – esdd
    Commented Mar 20, 2016 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .