
為什麼下面的 tikz 程式碼會將箭頭放在原來的位置?
\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{arrows.meta, bending}
\begin{document}
\begin{tikzpicture}
\draw[-Latex, double] (0:0.5) arc (0:180:0.5);
\end{tikzpicture}
\end{document}
如果刪除雙線、刪除bending
庫或使用標準latex
箭頭提示而不是Latex
中的箭頭提示arrows.meta
,我會得到預期的行為。
然而,不知何故,這三個功能的組合似乎被打破了。有什麼辦法可以讓這三個人一起工作嗎?
答案1
太長了;博士
透過新增兩行新行來重新定義以下巨集:
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\makeatletter
\def\pgf@draw@curved#1#2{%
% Prepare:
{%
\pgf@xc\pgf@xb % <--- adding new line
\pgfarrows@getid{#1}{#2}%
\pgf@xb\pgf@xc % <--- adding new line
% Do shift:
\expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid@shift\csname pgf@ar@ends@\pgf@arrow@id\endcsname%
\expandafter\let\expandafter\pgf@arrow@bending@mode\csname pgf@ar@bending@mode@#1\endcsname%
\ifx\pgf@arrow@bending@mode\pgfutil@empty\let\pgf@arrow@flex@mode\pgf@arrow@mode@is@flex\fi%
% do swap:
{%
\csname pgf@ar@saves@\pgf@arrow@id\endcsname%
\ifcase\pgf@arrow@flex@mode\relax%
\expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid\csname pgf@ar@visual@\pgf@arrow@id\endcsname% like flex
\or%
\expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid\csname pgf@ar@visual@\pgf@arrow@id\endcsname%
\or%
\expandafter\expandafter\expandafter\pgf@arrow@drawer@rigid\csname pgf@ar@ends@\pgf@arrow@id\endcsname%
\or%
\pgf@arrow@drawer@bend%
\fi%
% hull points inside the above
}%
\expandafter}%
% Transform to next tip:
\expandafter\pgf@xb\the\pgf@xb%
}
\def\pgf@arrow@drawer@rigid@shift#1#2#3{% tip end, back end, line end, sep
% Let xa be the actual back end of the current arrow plus the back end:
\advance\pgf@xb by#2%
\pgf@xa\pgf@xb%
% Update the xb:
\pgf@x#1%
\advance\pgf@x by\pgfarrowsep%
\advance\pgf@xb by-\pgf@x%
}
\def\pgf@arrow@drawer#1#2{%
% Prepare:
{%
\pgfarrows@getid{#1}{#2}%
% Do shift:
\expandafter\expandafter\expandafter\pgf@arrow@drawer@shift\csname pgf@ar@ends@\pgf@arrow@id\endcsname%
% Do slant:
\ifdim\pgfarrows@slant pt=0pt%
\else%
\pgftransformxslant{\pgfarrows@slant}%
\fi%
% do swap:
\ifpgfarrowswap%
\pgftransformyscale{-1}%
\fi%
{%
\csname pgf@ar@saves@\pgf@arrow@id\endcsname%
\pgfscope%
\pgf@arrows@color@setup%
\pgflowlevelsynccm\csname pgf@ar@cache@\pgf@arrow@id\endcsname%
\endpgfscope%
\pgf@arrows@rigid@hull%
}%
\expandafter}%
% Transform to next tip:
\expandafter\pgftransformxshift\expandafter{\the\pgf@xc}%
}
\def\test#1{\tikz\draw[double,-{#1}](1,0)..controls(1,1)and(0,1)..(0,0);}
\test{Rectangle[length=1,width=5,black]
Rectangle[length=2,width=4,black!80]
Rectangle[length=3,width=3,black!60]
Rectangle[length=4,width=2,black!40]
Rectangle[length=10,width=1,black!20]}
\test{latex[]}
\test{Straight Barb}
\test{Hooks}
\test{Arc Barb}
\test{Tee Barb}
\test{Classical TikZ Rightarrow}
\test{Computer Modern Rightarrow}
\test{Implies}
\test{Latex}
\test{Stealth}
\test{Kite}
\test{Square}
\test{Circle}
\test{Round Cap}
\test{Butt Cap}
\test{Triangle Cap}
\test{Fast Triangle}
\test{Fast Round}
\test{Rays}
\end{document}
更長的故事
尺寸\pgf@xb
用於記住箭頭尖端的位置。但由於某種原因,它被 中的某些內容覆蓋\pgfarrows@getid
。
所以一個解決方法就是使用\pgf@xc
後記住\pgf@xb
,然後再\pgf@xb
修復\pgfarrows@getid
。人們可以使用任何喜歡的維度暫存器。然而,從長遠來看,最好宣布一個新的維度。
甚至更長的故事
為什麼bending
選擇圖書館
如果沒有bending
庫,xshift 就會在群組外完成,這\pgfarrows@getid
會毀掉一切。也就是說,\pgf@xb
當群組終止時,覆蓋的內容就會消失,因此\pgf@xb
使用正確的內容。 (參見\pgf@arrow@drawer
。這是 的原始版本\pgf@draw@curved
。)
然而,由於bending
函式庫引入了三種需要對xshift進行不同處理的模式,因此xshift是在破壞一切\ifcase
的群組中完成的\pgfarrows@getid
。
為什麼有些箭頭尖端不會受到影響?
一些箭頭提示與我們在數學模式中使用的箭頭提示重複。這些箭頭與 PGF/Ti 無關kZ 的參數。長話短說:latex
一個例子。
對於諸如 之類的箭頭提示Latex
,它們\pgfarrows@getid
涉及對 PGF/Ti 的一些計算kZ 的參數。具體來說,他們需要運行\pgfarrowslinewidthdependent
。
為什麼double
?
因為當double
使用 時, 的計算\pgfarrowslinewidthdependent
變得更加複雜,並且\pgf@xb
被覆蓋!
答案2
載入bending
庫時,繪製箭頭提示的預設方法從變更quick
為flex
。flex
比 的計算成本更高quick
,但比 更便宜bend
,並且通常會給出更好的結果。但不總是。您可以quick
透過明確指定來恢復預設值:
\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{arrows.meta, bending}
\begin{document}
\begin{tikzpicture}
\draw[-Latex, double] (0:0.5) arc (0:180:0.5);
\scoped[yshift=10mm]{\draw[-{Latex[quick]}, double] (0:0.5) arc (0:180:0.5);}
\end{tikzpicture}
\end{document}
然而,這三種方法都沒有給出很好的結果——quick
只是發生了最好的可用弊端。