1
\documentclass{article}

\usepackage[pdfpagelabels=true]{hyperref}

\begin{document}

\tableofcontents

\newpage

\section{S1}
\label{s1}

\subsection{SS1}
\label{ss1}
Subsection 1
\newpage

\subsection{SS2}
\label{ss2}
Subsection 2
\newpage

\subsection{SS3}
\label{ss3}
Subsection 3.  For more info, see \hyperref[ss2]{Subsection 2, pg. How Do I Put The Target Page Number Here}.
\newpage

\end{document}

I want Subsection 3 to read: "Subsection 3. For more info, see Subsection 2, pg. 3".

2
1

\pageref would work here.

\documentclass{article}

\usepackage[pdfpagelabels=true]{hyperref}

\begin{document}

\tableofcontents

\newpage

\section{S1}
\label{s1}

\subsection{SS1}
\label{ss1}
Subsection 1
\newpage

\subsection{SS2}
\label{ss2}
Subsection 2
\newpage

\subsection{SS3}
\label{ss3}
Subsection 3.  For more info, see \hyperref[ss2]{Subsection 2, pg. 
\pageref{ss2}}.
\newpage

\end{document}
3
  • Is there a way to reference the page number without having to list the label id twice? – mpr May 17 '18 at 15:11
  • 1
    @mpr There are many possibilities, you could write a macro for it, or you look at some of the packages like in Mico's answer or in Moewe's comment. It really depends on the overall structure of your document. Notice also that the current version has certain advantages, it allows you to refer to a special bit in the subsection that is not on the same page as the head of the subsection. – user121799 May 17 '18 at 15:16
  • Yeah it just occurred to me that a macro would be perfect for my setup, and also allow me to possibly use cref or other things later. Thanks. – mpr May 17 '18 at 15:17
1

You could employ the cleveref package and its highly customizable \cref and \cpageref commands.

(The colors in the following screenshot highlight the hyperlink targets; if you don't want colors, be sure to set the allcolors=black option while loading hyperref.)

enter image description here

\documentclass{article}

\usepackage[pdfpagelabels=true,colorlinks=true]{hyperref}
\usepackage[capitalize,nameinlink]{cleveref}
\crefname{subsection}{subsection}{subsections}
\crefname{page}{pg.}{pgs.}

\begin{document}
\tableofcontents
\newpage

\section{S1}\label{s1}
Section 1

\subsection{SS1}
\label{ss1}
Subsection 1.1
\newpage

\subsection{SS2}
\label{ss2}
Subsection 1.2
\newpage

\subsection{SS3}
\label{ss3}
Subsection 1.3.  For more info, see \Cref{ss2}, \cpageref{ss2}.

\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.