Tikz 图片流程图,块内有标签并在正文中引用它们

Tikz 图片流程图,块内有标签并在正文中引用它们

我需要一种方法,将标签放在流程图的块内,以某种方式对它们进行编号或枚举,然后在正文中引用这些块。我需要在 PDF 中单击时直接转到该节点的超链接。

我已经有一个几乎可以满足我要求的解决方案。我不是 *TeX 专家,所以我将以下帖子拼凑在一起:

自定义计数器和交叉引用

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

\documentclass{article}
\usepackage{hyperref}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\newcounter{BlockCounter}

\begin{document}

\newcommand{\labelBlock}[1]{%
\refstepcounter{BlockCounter}%
\hypertarget{#1}{}(\theBlockCounter\label{#1})%
}

\newcommand{\refBlock}[1]{%
\hyperref[#1]{Block~\ref*{#1}}% (see p. 18 of the hyperref manual)
}

\begin{figure}[tbp]
    \centering
    \tikzstyle{block} = [draw, fill=black!20, rectangle, minimum height=2em, minimum width=6em]
    \begin{tikzpicture}[auto, node distance=2cm,>=latex']
        \node [block] (aaa) {\labelBlock{blockA} Step one};
        \node [block, below left=of aaa] (bbb) {\labelBlock{blockB} Step two-left};
        \node [block, below right=of aaa] (ccc) {\labelBlock{blockC} Step two-right};
        \draw [draw,->] (aaa) -- node {left} (bbb);
        \draw [draw,->] (aaa) -- node {right} (ccc);
    \end{tikzpicture}
    \caption{Caption here.}
\end{figure}

Reference to \refBlock{blockA}. Reference to \refBlock{blockB}. Reference to \refBlock{blockC}.

\end{document}

产生以下结果

在此处输入图片描述

问题:

  1. 我如何控制超目标的精确位置?我尝试使用提升框,但没有效果。我需要它稍微高于块。
  2. 如何将枚举更改为 A、B、C,而不是 1、2、3?

答案1

你可以把所有激活 hyperref 的命令放入其中,\raisebox并将打印的计数器留在其原始位置:

\documentclass{article}
\usepackage{hyperref}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\newcounter{BlockCounter}
\renewcommand{\theBlockCounter}{\Alph{BlockCounter}}

\begin{document}

\newcommand{\labelBlock}[1]{%
\smash{\raisebox{15pt}{\refstepcounter{BlockCounter}\hypertarget{#1}{}\label{#1}}}%
(\theBlockCounter)%
}

\newcommand{\refBlock}[1]{%
\hyperref[#1]{Block~\ref*{#1}}% (see p. 18 of the hyperref manual)
}

\begin{figure}[tbp]
    \centering
    \tikzstyle{block} = [draw, fill=black!20, rectangle, minimum height=2em, minimum width=6em]
    \begin{tikzpicture}[auto, node distance=2cm,>=latex']
        \node [block] (aaa) {\labelBlock{blockA} Step one};
        \node [block, below left=of aaa] (bbb) {\labelBlock{blockB} Step two-left};
        \node [block, below right=of aaa] (ccc) {\labelBlock{blockC} Step two-right};
        \draw [draw,->] (aaa) -- node {left} (bbb);
        \draw [draw,->] (aaa) -- node {right} (ccc);
    \end{tikzpicture}
    \caption{Caption here.}
\end{figure}

Reference to \refBlock{blockA}. Reference to \refBlock{blockB}. Reference to \refBlock{blockC}.

\end{document}

相关内容