我修改了MWE使 TikZ 節點可超連結當我將樣本節點旋轉 60 度時得到以下結果:
我的願望是超連結與框一起旋轉。如..所示這裡,可以\rotatebox{...}
在節點內使用,但這不會給出很好的結果:它旋轉節點內的文本,而不是邊界(或連結)。
修改後的 MWE 顯示了這兩種不太完美的結果,如下所示。
\documentclass{article}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{calc}
\begin{document}
\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}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
%xelatex needs \XeTeXLinkBox, won't create a link unless it
%finds text --- rules don't work without \XeTeXLinkBox.
%Still builds correctly with pdflatex and lualatex
}
}
}
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=60] {Go to Page Two};
\bigskip
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo] {\rotatebox{30}{\hyperref[pagetwo]{I said, Page Two}}};
\clearpage
\hypertarget{pagetwo}{Page Two}
\end{document}
答案1
傾斜/傾斜/旋轉/傾斜的超連結是可能的!
PDF 規格定義了註釋字典/QuadPoints
中的條目/Link
,該條目定義了任意數量的四邊形的角座標,這些四邊形只需完全內接在通常的水平連結矩形內,並進一步確定超連結的滑鼠敏感區域。
原則,任意形狀文檔頁面中的區域可以變成超連結使用這種方法,只需將多個四邊形疊加即可。各個四邊形不需要是長方形,也不需要水平對齊。
唉,像往常一樣,這類高級 PDF 功能需要 Acrobat Reader。
例子(注意:對於 Acrobat Reader):
\documentclass{article}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{calc}
\makeatletter
% patch hyperref to also include the /QuadPoints array
\let\Hy@setpdfborderOrig\Hy@setpdfborder
\def\Hy@setpdfborder{
\QuadPoints
\Hy@setpdfborderOrig
}
\def\writeAux{\protected@write\@mainaux}
\def\QuadPoints{}
\makeatother
\newcounter{srcnd}
\begin{document}
\tikzset{
hyperlink node/.style={
alias=sourcenode,
append after command={
let \p1 = (sourcenode.south west),
\p2 = (sourcenode.south east),
\p3 = (sourcenode.north east),
\p4 = (sourcenode.north west),
\p5 = (sourcenode.center)
in
node [inner sep=0pt, outer sep=0pt,at=(\p1)] {\pdfsavepos%
\writeAux{}{%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.x1\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastxpos sp}}%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.y1\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastypos sp}}}%
}
node [inner sep=0pt, outer sep=0pt,at=(\p2)] {\pdfsavepos%
\writeAux{}{%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.x2\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastxpos sp}}%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.y2\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastypos sp}}}%
}
node [inner sep=0pt, outer sep=0pt,at=(\p3)] {\pdfsavepos%
\writeAux{}{%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.x3\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastxpos sp}}%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.y3\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastypos sp}}}%
}
node [inner sep=0pt, outer sep=0pt,at=(\p4)] {\pdfsavepos%
\writeAux{}{%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.x4\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastxpos sp}}%
\string\expandafter\string\xdef\string\csname\space srcnd\thesrcnd.y4\string\endcsname{%
\noexpand\hypercalcbp{\noexpand\number\pdflastypos sp}}}%
}
node [inner sep=0pt, outer sep=0pt,at=(\p5)] {%
\makebox[0pt][c]{{%
\edef\QuadPoints{/QuadPoints [
\csname srcnd\thesrcnd.x1\endcsname\space\csname srcnd\thesrcnd.y1\endcsname\space
\csname srcnd\thesrcnd.x2\endcsname\space\csname srcnd\thesrcnd.y2\endcsname\space
\csname srcnd\thesrcnd.x3\endcsname\space\csname srcnd\thesrcnd.y3\endcsname\space
\csname srcnd\thesrcnd.x4\endcsname\space\csname srcnd\thesrcnd.y4\endcsname\space
]}%
\hyperlink{#1}{%
\raisebox{-\height}{%
\tikz \useasboundingbox (\p1) -- (\p2) -- (\p3) -- (\p4) -- cycle;
}%
}%
}}%
\stepcounter{srcnd}%
}
}
}
}
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=0] {Go to Page Two};
\bigskip
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=60] {Go to Page Two};
\bigskip
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=40] {Go to Page Two};
\bigskip
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=135] {I said, Page Two};
\clearpage
\hypertarget{pagetwo}{Page Two}
\end{document}
答案2
考慮到 percusse 提到的限制(並感謝 Jasper Habicht 的評論,該評論是在我完成測試時發布的),這裡是一個計算旋轉角度的「改進」版本。
\documentclass{article}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{calc}
\begin{document}
\tikzset{
hyperlink node/.style={
alias=sourcenode,
append after command={
let \p1 = (sourcenode.north west),
\p2=(sourcenode.south east),
\p3 = (sourcenode.south west),
\n1={\x2-\x1},
\n2={\y1-\y2},
\n3={atan2(\y2-\y3,\x2-\x3)},
\n4={veclen(\y2-\y3,\x2-\x3)},
\n5={veclen(\y1-\y3,\x1-\x3)}
in
node [inner sep=0pt, outer sep=0pt,anchor=south
west,at=(\p3),rotate=\n3]
{\hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n4}{\n5}}}}}
%xelatex needs \XeTeXLinkBox, won't create a link unless it
%finds text --- rules don't work without \XeTeXLinkBox.
%Still builds correctly with pdflatex and lualatex
}
}
}
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=0] {Go to Page Two};
\bigskip
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=60] {Go to Page Two};
\bigskip
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo,rotate=40] {Go to Page Two};
\bigskip
\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo] {\rotatebox{30}{\hyperref[pagetwo]{I said, Page Two}}};
\clearpage
\hypertarget{pagetwo}{Page Two}
\end{document}
xelatex 和其他編譯器的輸出不同。該版本針對 xelatex 進行了「最佳化」。