太長了;博士

太長了;博士

為什麼下面的 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庫時,繪製箭頭提示的預設方法從變更quickflexflex比 的計算成本更高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只是發生了最好的可用弊端。

相關內容