1

I am using moderncv - and have a number of cventry items, that contain individual items:

\section{Work Experience}
\cventry{Jan.~2010 -- Mar.~2013}{Project1}{Company1}{}{}{I worked on the following: \begin{itemize*}
    \item Wrote foo \label{tocBar}
    \item Made bar \label{tocBaz}
    \item Improved baz 
\end{itemize*}
}
\cventry{Apr.~2013 -- Mar.~2014}{Project2}{Company2}{}{}{I worked on the following: \begin{itemize*}
    \item Wrote more stuff \label{tocTheory}
    \item And improved theory of everything 
\end{itemize*}
}

Now, I want to create internal (clickable) links that point to some specific \item - e.g. tocBar. Unfortunately, when I try to use \hyperref[some text]{tocBar}, the link generated in the PDF points to the beginning of the section instead of the \item itself.

Similar behavior if I use a \pageref{tocBar} - though in that case, the page number created is correct; it's just the link generated that is wrong (and takes me to the beginning of the section instead of the \item).

Is there anything I can do to create properly working links to individual items?

EDIT: I added a complete, reproducible example here: https://gist.github.com/ttsiodras/76572cb3446cb8b1ad878640337e45b5 Try clicking the generated link in the 1st page, and you'll see it navigates to the 2nd page instead of the 3rd one (that actually contains the element pointed to).

  • 1
    Hi and welcome. It would be much easier for us to help you if you add a full Minimal Working Example (MWE) that includes everything from \documentclass to \end{documant} – Elad Den May 31 '20 at 9:33
  • @EladDen: I will try - but to demonstrate the effect, the text must be large enough to cause a multi-page document. I will insert lots of "Lorem ipsum" filler, but that probably means the example will be too big to paste verbatim in the question body. is a gist in Github an acceptable workaround? – ttsiodras May 31 '20 at 9:49
  • @EladDen Added a fully working example. – ttsiodras May 31 '20 at 10:06
1

You are using \usepackage[options...]{hyperref}, You should use \AtBeginDocument{\hypersetup{colorlinks=true,urlcolor=color1,linkcolor=color1}} to set the options.

This is because hyperref is already called in the moderncv.sty file and the settings for the package are defined AtBeginDocument, so if you simply try to use the hypersetup command it would either not work or throw an error.

The sections and items are defined differently in moderncv than in article. No counters and the depths are all off. Therefore when you put a \label{} it will point to the latest section. To fix that simply use \phantomsection{} where you want the cross-ref to point to.

Also, I used color1 as the link's color, as otherwise, you'd get a blue that is not consistent with the rest of the format.

My MWE:

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage{mdwlist}
\usepackage{lipsum}
%\usepackage[colorlinks=true,urlcolor=blue,linkcolor=blue]{hyperref} <-- This will throw an error

\firstname{John}
\familyname{Doe}
\email{John.Doe@gmail.com}
\homepage{www.johndoe.com}
\makeatletter
\makeatother
\AtBeginDocument{\hypersetup{colorlinks=true,urlcolor=color1,linkcolor=color1}} %<--- This is how you set it up
\begin{document}
\makecvtitle
\section{Summmary}
\begin{itemize*}
    \item For my work on foo, please see \hyperref[tocAlpha]{this information}. %<-- notice color
\end{itemize*}
\section{Experience}\label{sec:experience}
\subsection{Professional coding}
    \cventry{Jan.~2016 -- today}{Software Engineer}{Space colony}{}{}{Over the last 4 years...
    \begin{itemize*}
        \item Work on \lipsum[1-2] %Shorter and easier, no?
        \item More work on \lipsum[1-2]
        \item Extra work on \lipsum[1-2]
        %\item 
\end{itemize*}
}
    \cventry{year--year}{Job title}{Employer}{City}{}{See section \hyperref[sec:experience]{some text}}

    \cventry{Jan.~2010 -- Jan.~2016}{Software Engineer}{Mars colony}{}{}{Over the last 6 years...\begin{itemize*}
            \phantomsection{}\label{tocAlpha}
        \item Work on foo \lipsum[1-2]
        \item More work on \lipsum[1-2]
        \item Extra work on \lipsum[1-2]
\end{itemize*}
}
\end{document}

Note, I used lipsum package for the example to make it a little more... minimal :)

  • Hi, Elad. I just tried your example - the PDF generated from pdflatex ( Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Arch Linux) contains a link "please see this information" that takes me in page 1 (instead of the page with "work on foo". I use "Evince" to open the PDF - can you please report on what version of pdflatex you use? And also, which PDF reader? – ttsiodras Jun 1 '20 at 13:57
  • Hi, sorry about that, gave you the first version of the answer where I thought the problem was that hyperref was simply not working. You need to use \phantomsection{} for the label to work properly. This is fixed in the answer as well. – Elad Den Jun 2 '20 at 6:57
  • Perfect - thank you! – ttsiodras Jun 3 '20 at 11:41

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.