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.

  • 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. – Ulrike Fischer Mar 19 '16 at 16:16
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}
  • 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 Mar 19 '16 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 Mar 20 '16 at 17:05

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.