如何跳转到文章中的任意页面

如何跳转到文章中的任意页面

我想制作一个宏,通过它当我点击指定的对象时我可以跳转到我想要的任何页面,如下所示:

\gotopage{3}{object selected}%然后转到第三页

该对象可以是文本、图形等等。

而且我不喜欢在每一页都贴标签,尤其是当一篇文章有​​很多页时。

我怎样才能做到这一点?

下面是一个 MWE 和相关图表来展示我的想法:

\documentclass{article}
\usepackage{calc,ifthen,eso-pic,picture,xparse,lastpage,refcount,tikz}
\AtBeginDocument{
 \newcounter{totalpage}
 \setcounter{totalpage}{\getpagerefnumber{LastPage}}
}
\begin{document}
\AddToShipoutPictureBG{\AtPageCenter{%
   \put(0.5\paperwidth-0.5\marginparwidth,0.5\textheight) {%
      \scalebox{0.7} {%
        \begin{tikzpicture}[baseline=(current bounding box.north)]%
          \foreach \i in {1,...,\thetotalpage}{%
            \ifnum\value{page}=\i\relax%
               \tikzset{pn/.style={fill=red,font=\bfseries}}
            \else%
               \tikzset{pn/.style={fill=gray,opacity=0.5}}%
            \fi%
            \path[radius=0.5cm,scale=1,text=white,pn](0,-\i) circle node[scale=1.5]{\i};
          }%\foreach
        \end{tikzpicture}%
      }%\scalebox
    }%put
}}
first page
\clearpage
second page
\clearpage
third page    
\end{document} 

在此处输入图片描述

更新的 MWE:

\documentclass{article}
\usepackage{calc,ifthen,eso-pic,picture,xparse,lastpage,refcount,tikz,hyperref}
\AtBeginDocument{
 \newcounter{totalpage}
 \setcounter{totalpage}{\getpagerefnumber{LastPage}}
}
\begin{document}
\AddToShipoutPictureBG{\AtPageCenter{%
   \put(0.5\paperwidth-0.5\marginparwidth,0.5\textheight) {%
      \scalebox{0.7} {%
        \begin{tikzpicture}[baseline=(current bounding box.north)]%
          \foreach \i in {1,...,\thetotalpage}{%
            \ifnum\value{page}=\i\relax%
               \tikzset{pn/.style={fill=red,font=\bfseries}}
            \else%
               \tikzset{pn/.style={fill=gray,opacity=0.5}}%
            \fi%
            \hyperlink{page.\i}{%   
            \path[radius=0.5cm,scale=1,text=white,pn](0,-\i) circle node[scale=1.5]{\i};
          }%\hyperlink  
          }%\foreach
        \end{tikzpicture}%
      }%\scalebox
    }%put
}}
first page
\clearpage
second page
\clearpage
third page    
\end{document} 

在此处输入图片描述

答案1

page.<number>hyperref 默认为每个页面创建具有以下名称的目标(锚点) :

\documentclass{article}

\usepackage{hyperref}
\begin{document}
\hyperlink{page.1}{page 1}
\hyperlink{page.2}{page 2}
\hyperlink{page.3}{page 3}
\hyperlink{page.i}{page i}
page 1
\newpage
page 2
\newpage

page 3

\newpage \pagenumbering{roman}

roman i

\end{document}

在此处输入图片描述

答案2

我的解决方案是将链接放在堆叠在圆圈数字顶部的空框中。

\documentclass{article}
\usepackage{calc,ifthen,eso-pic,picture,xparse,lastpage,refcount,tikz}
\usepackage{hyperref}
\newcommand\refbox[1]{\smash{\rlap{\hspace{-3mm}%
  \hyperlink{page.#1}{\rule[-3mm]{0pt}{9mm}\hspace{9mm}}}}}

\AtBeginDocument{
 \newcounter{totalpage}
 \setcounter{totalpage}{\getpagerefnumber{LastPage}}
}
\begin{document}
\AddToShipoutPictureBG{\AtPageCenter{%
   \put(0.5\paperwidth-0.5\marginparwidth,0.5\textheight){%
      \scalebox{0.7}{%
        \begin{tikzpicture}[baseline=(current bounding box.north)]%
          \foreach \i in {1,...,\thetotalpage}{%
            \ifnum\value{page}=\i\relax%
               \tikzset{pn/.style={fill=red,font=\bfseries}}
            \else%
               \tikzset{pn/.style={fill=gray,opacity=0.5}}%
            \fi%
            \path[radius=0.5cm,scale=1,text=white,pn](0,-\i)
              circle node[scale=1.5]{\refbox{\i}\i};
          }%\foreach
        \end{tikzpicture}%
      }%\scalebox
    }%put
}}
first page
\clearpage
second page
\clearpage
third page    
\end{document} 

输出图像

答案3

工作正常,只是右边的数字没有堆叠。

\documentclass{article}
\usepackage{calc,ifthen,eso-pic,picture,xparse,lastpage,refcount,tikz}
\AtBeginDocument{
 \newcounter{totalpage}
 \setcounter{totalpage}{\getpagerefnumber{LastPage}}
}

% For cross referencing
\usepackage{hyperref}


% Arrange labeling every page
% \usepackage{everypage}
% \AddEverypageHook{\phantomsection\label{pagelabel\thepage}}
% Comment out the followind and uncomment the above two lines if you
% get, ERROR: Undefined control sequence.  --- TeX said --- l.12
\AddToHook{shipout/background}{\phantomsection\label{pagelabel\thepage}}


% Dummy text
\usepackage{blindtext}

\begin{document}

\AddToShipoutPictureBG{\AtPageCenter{%
    \put(0.5\paperwidth-0.5\marginparwidth,0.5\textheight) {%
      \scalebox{0.7} {%
        \foreach \i in {1,...,\thetotalpage}{%
          \ifnum\value{page}=\i\relax%
          \tikzset{pn/.style={fill=red,font=\bfseries}}
          \else%
          \tikzset{pn/.style={fill=gray,opacity=0.5}}%
          \fi%
          \hyperref[pagelabel\i]{\begin{tikzpicture}[baseline=(current bounding box.north)]%
              \path[radius=0.5cm,scale=1,text=white,pn](0,\i) circle node[scale=1.5]{\i};
            \end{tikzpicture}}\\}%
      }%\foreach
    }%\scalebox
  }%put
}

first page
\clearpage


second page

\clearpage
third page

\Blindtext
\Blindtext

\end{document}

相关内容