TikZ 文档导航(\label 和 \ref 命令)

TikZ 文档导航(\label 和 \ref 命令)

我目前是一名工程专业的大学生。我已经使用 LaTeX 几年了,但不知道该如何解决以下问题。

在澳大利亚,有标准描述了技术图纸中引用的方式。我试图在 LaTeX 中创建一种方法,以便我创建一组图纸(所有 TikZ 图片),其中剖面图、立面图和细节都可以在文档中导航(使用 hyperref 包)。不幸的是,我目前收到一条错误消息,指出标签未定义,因此引用中断。我认为这是因为标签未与“图形”类型环境相关联。

理想情况下,这些链接应以文本形式显示,点击后,浏览者将转到显示该部分的页面。此外,如果可能的话,最好能引用显示该部分的页面。

下面我提供了一个简单的例子来表达我的想法。也许有人已经设法解决了这个问题。

\documentclass{report}

\usepackage{tikz,hyperref}

\begin{document}

\begin{tikzpicture}
     \node at ( 20 mm , 20 mm ) {Hello World!\label{hello}} ;
\end{tikzpicture}

\newpage

\begin{tikzpicture}
     \node at (20 mm , 20 mm ) {Reference\ref{hello}};
     % This (hopefully) would make it possible to link
     % from Page X to Y within the .pdf document.
\end{tikzpicture}

\end{document}

感谢所有花时间阅读此文的人,我期待收到您的回复。

答案1

您希望能够使用超链接从一个图形导航到另一个图形,对吗?在这种情况下,您应该hyperref直接使用包的宏,即\hypertarget{<label>}{<target text>}和,而不是添加到和 的\hyperlink{<label>}{<link text>}隐式宏:\label\ref

\documentclass{report}

\usepackage{tikz,hyperref}

\begin{document}

\begin{tikzpicture}
    \node [draw] at ( 20 mm , 20 mm ) {\hypertarget{hello}{Hello World!}} ;
\end{tikzpicture}

\newpage

\begin{tikzpicture}
    \node [draw] at (20 mm , 20 mm ) {\hyperlink{hello}{Reference}};
\end{tikzpicture}

\end{document}

然后“参考”是指向“Hello World”的超链接。默认情况下,它周围会添加一个彩色框架。您可以使用hyperref手册中描述的选项进行更改。

这里的一个问题是,超锚点位于基线“Hello World”文本。因此,如果您跳转到那里,您实际上看不到文本,因为它就在窗口顶部上方。我通常通过将\hypertarget空文本放入\raisebox0pt 官方高度并将其提升到文本上方一定高度来解决这个问题。然后链接跳转到一个显示窗口顶部正下方目标文本的屏幕:

\documentclass{report}

\usepackage{tikz,hyperref}

\begin{document}

\begin{tikzpicture}
    \node [draw] at ( 20 mm , 20 mm ) {\raisebox{3ex}[0pt]{\hypertarget{hello}{}}Hello World!} ;
\end{tikzpicture}

\newpage

\begin{tikzpicture}
    \node [draw] at (20 mm , 20 mm ) {\hyperlink{hello}{Reference\strut}};
     % This (hopefully) would make it possible to link
     % from Page X to Y within the .pdf document.
\end{tikzpicture}

\end{document}

答案2

问题可能出在参考编号上。在这种情况下,您可以使用\pageref。有了\section,您就可以使用\ref{...}

\documentclass{report}    
\usepackage{tikz,hyperref}    
\begin{document}

\begin{tikzpicture}
     \node[draw] at ( 20 mm , 20 mm ) {Hello World!\label{hello}} ;
\end{tikzpicture} 
\newpage

\begin{tikzpicture}
     \node[draw] at (20 mm , 20 mm ) {Reference: \pageref{hello}};
     % This (hopefully) would make it possible to link
     % from Page X to Y within the .pdf document.
\end{tikzpicture}    
\end{document}

\section

\documentclass{report}

\usepackage{tikz,hyperref}

\begin{document}
\section{}
\begin{tikzpicture}
     \node[draw] at ( 20 mm , 20 mm ) {Hello World!\label{hello}} ;
\end{tikzpicture} 
\newpage

\section{}
\begin{tikzpicture}
     \node[draw] at (20 mm , 20 mm ) {Reference: \ref{hello}};
\end{tikzpicture}
\end{document}   

在此处输入图片描述

相关内容