我正在尝试制作一个小的思维导图,以便一些子节点可以超链接。我尝试遵循给出的建议这里,关于新的节点样式hyperlink node
,但以下MWE编译时出现错误。
为了阐明 MWE 的结构,它首先定义样式hyperlink node
,然后在行中使用
node[concept, hyperlink node=www.google.com] {practical}
以下是 MWE(改编自这里):
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage{tikz}
\usetikzlibrary{mindmap,trees}
\begin{document}
\pagestyle{empty}
\tikzset{
hyperlink node/.style={
alias=sourcenode,
append after command={
let \p1 = (sourcenode.north west),
\p2=(sourcenode.south east),
\n1={\x2-\x1},
\n2={\y1-\y2} in
node [inner sep=0pt, outer sep=0pt,anchor=north west,at=(\p1)] {\hyperlink{#1}{\phantom{\rule{\n1}{\n2}}}}
}
}
}
\begin{tikzpicture}
\path[mindmap,concept color=black,text=white]
node[concept] {Computer Science}
[clockwise from=0]
child[concept color=green!50!black] {
node[concept, hyperlink node=www.google.com] {practical}
[clockwise from=90]
child { node[concept] {algorithms} }
child { node[concept] {data structures} }
child { node[concept] {pro\-gramming languages} }
child { node[concept] {software engineer\-ing} }
}
child[concept color=blue] {
node[concept] {applied}
[clockwise from=-30]
child { node[concept] {databases} }
child { node[concept] {WWW} }
}
child[concept color=red] { node[concept] {technical} }
child[concept color=orange] { node[concept] {theoretical} };
\end{tikzpicture}\end{document}
如果能得到关于如何使 TikZ 中的思维导图可超链接的建议或帮助解决此问题,我们将不胜感激。
答案1
最快的解决方法是直接将其放入节点内部\hyperlink
,例如:
node[concept] {\hyperlink{pract}{practical}}
这不会改变concept
风格的外观。
代码:
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage{tikz}
\usetikzlibrary{mindmap}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
\path[mindmap,concept color=black,text=white]
node[concept] {Computer Science}
[clockwise from=0]
child[concept color=green!50!black] {
node[concept] {\hyperlink{pract}{practical}}
[clockwise from=90]
child { node[concept] {algorithms} }
child { node[concept] {data structures} }
child { node[concept] {pro\-gramming languages} }
child { node[concept] {software engineer\-ing} }
}
child[concept color=blue] {
node[concept] {applied}
[clockwise from=-30]
child { node[concept] {\hyperlink{datab}{databases}} }
child { node[concept] {WWW} }
}
child[concept color=red] { node[concept] {technical} }
child[concept color=orange] { node[concept] {theoretical}
};
\end{tikzpicture}
\newpage
\begin{itemize}
\item \hypertarget{pract}{Practical}: here is some description.
\item \hypertarget{datab}{Databases}: here is some description.
\end{itemize}
\end{document}
答案2
在这个解决方案中,我使用path picture
而不是append after command
。
(注意:超链接始终是一个矩形区域......)
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage{tikz}
\usetikzlibrary{mindmap,trees,calc}
\begin{document}
\pagestyle{empty}
\tikzset{
hyperlink node/.style={
postaction={
path picture={
\path let
\p1 = (path picture bounding box.south west),
\p2 = (path picture bounding box.north east),
\p3 = (\x2-\x1,\y2-\y1)
in
(path picture bounding box.center)
node[inner sep=0pt,anchor=center,outer sep=0pt]
{\hyperlink{#1}{\phantom{\rule{\x3}{\y3}}}};
}
},
},
}
\begin{tikzpicture}
\path[mindmap,concept color=black,text=white]
node[concept] {Computer Science}
[clockwise from=0]
child[concept color=green!50!black] {
node[concept, hyperlink node=www.google.com] {practical}
[clockwise from=90]
child { node[concept] {algorithms} }
child { node[concept] {data structures} }
child { node[concept] {pro\-gramming languages} }
child { node[concept] {software engineer\-ing} }
}
child[concept color=blue] {
node[concept] {applied}
[clockwise from=-30]
child { node[concept] {databases} }
child { node[concept] {WWW} }
}
child[concept color=red] { node[concept] {technical} }
child[concept color=orange] { node[concept] {theoretical} };
\end{tikzpicture}
\end{document}