4

So I know that the problem is at

\setcounter{secnumdepth}{0}

But I don't know if there is a fix to this (without deleting this line, since I don't want numbered sections), since the link in ToC is fine. Basically the effect I want is to have a clickable link on one arbitrary word I write (just like the URL where the link is behind the text).

\documentclass[12pt]{article}
\usepackage{hyperref}
\title{Test}
\setcounter{secnumdepth}{0}
\begin{document}
\maketitle
\tableofcontents
\section{Test}\label{sec:test}
There should be a clickable link: \ref{sec:test}\\
But this works:
\autoref{sec:test}\\
And this also works:
\pageref{sec:test}\\
\end{document}
0

1 Answer 1

6

\ref will return the number of the link, and you've removed that by using \setcounter{secnumdepth}{0}. So, your choices are \nameref{<label>} or \hyperlink[<label>]{<text>}:

enter image description here

\documentclass{article}
\usepackage{hyperref}
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\section{Test}\label{sec:test}
There should be a clickable link: \nameref{sec:test} or \hyperref[sec:test]{TEST} \par
But this works: \autoref{sec:test} \par
And this also works: \pageref{sec:test}
\end{document}

You must log in to answer this question.

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