3

Can someone tell me how to color/represent (only internal) hyperlinks in a pdf differently (preferably just by using LyX,i.e. without diving deeper into pure latex) ? For example I would like the links from the table of contents to the separate sections my pdf to be put in a blue box, but all the other links (links to formulas or footnotes) to be green-coloured text.

My problem is, if I set a color and a "style"(in a box/text-colored) all links are like that and I see no way of differentiating between them.

My version of LyX is 2.

3

I don’t know Lyx, so I can only show you a pure LaTeX solution:
You can use \hypersetup several times:

\documentclass{article}
\usepackage[latin,english]{babel} % needed for "blindtext",
                                  % "english" is the active language
\usepackage{blindtext,lipsum,kantlipsum}

\usepackage[%
  colorlinks=true,% 
  linkcolor=red,%
  linktoc=all,%
]{hyperref}

\begin{document}

\tableofcontents

\newpage

\hypersetup{%
  linkcolor=blue,%
}

\section{Package \texttt{blindtext}}

\subsection{English blindtext}\label{btext-en}
See also package \hyperref[klipsum]{\ttfamily kantlipsum}.
\medskip

\blindtext[1]

\subsection{Latin blindtext}\label{btext-la}
Compare package \hyperref[lipsum]{\ttfamily lipsum}.
\medskip

{\selectlanguage{latin}% note the grouping
\blindtext[1]}

\newpage

\hypersetup{%
  linkcolor=green,%
}

\section{Package \texttt{kantlipsum}}\label{klipsum}
See also package \hyperref[btext-en]{\texttt{blindtext} with English text}.
\medskip

\kant[1]

\section{Package \texttt{lipsum}}\label{lipsum}
Compare package \hyperref[btext-la]{\texttt{blindtext} with pseudo-Latin text}.
\medskip

{\selectlanguage{latin}% actually not needed here
\lipsum[1]}% note the grouping again

\end{document}

First I’ve defined red link colour inside the hyperref package options (the two others are for better recognizability). This could have been done in a first separate \hypersetup, too.

After the table of contents I’ve put one \hypersetup for blue link colour, and later I set another one, just to show you the opportunity.

  • Thanks, your solution almost worked for me. What didn't worked yet, is making a box around the links in the TOC, but not around all the others. If I add \hypersetup{colorlinks=false} before the \begin{document} line, the all my links don't have boxes (and subsequent \hypersetup commands can't change this - although they can change the color of the box...). The same goes for no "\hypersetup{colorlinks=false}" and the "=true" value, the same behaviour holds: Either all or none. Changing the colours works fine though. Do you have any ideas? – l7ll7 Feb 24 '12 at 14:57
  • @user10324: Sorry, the part with the box I’ve overlooked. I have no idea, how this could be done. But why do you want boxes in the toc, and later coloured links? You could also change the option linktoc or replace it by linktocpage. See for that in the README.pdf of hyperref documentation. (How about linkcolor=black for the toc?) – Speravir Feb 24 '12 at 15:22

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.