1

I have a roblem with LaTex involving the hyperref package. Consider the following example:

\documentclass{scrartcl}
\usepackage{hyperref}

\begin{document}

\tableofcontents

\section{Some section}

\section*{Some starred section}
\label{starred-section}
\addcontentsline{toc}{section}{\hyperref[starred-section]{Starred section}}

\end{document}

I use XeLaTex to compile this which works perfectly fine but there is one minor problem with the output, I posted a screenshot below. The pdf itself looks completely fine, but the table of contents AS DISPLAYED BY THE PDF VIEWING PROGRAM (preview on mac in my case) is screwed up by hyperref, see the red box. I checked whether this is an issue of preview, but Adobe reader displays the table of contents in the same way. Does anyone know a solution to that? Thank you! enter image description here

migrated from stackoverflow.com Oct 13 '15 at 3:13

This question came from our site for professional and enthusiast programmers.

1

Actually you don't need to link any table-of-contents(toc) entry to a section or something. Since you are using hyperref all toc-entrys are already links and this is also what made this error come up. If you need that label for the section for somewhere else it will work perfectly fine without any errors, but don't use it for the toc.

This is what the working code looks like:

\documentclass{scrartcl}
\usepackage[hidelinks]{hyperref} 
%hidelinks removes the ugly boxes around the links, if you want that.
%Else just remove the '[hidelinks]' again

\begin{document}

\tableofcontents

\section{Some section}

\section*{Some starred section}
\label{starred-section} %remove it if not needed elsewhere!
\addcontentsline{toc}{section}{Starred section}

\end{document}

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.