修復“指南針”中箭頭的填充

修復“指南針”中箭頭的填充

如何修復箭頭的顏色?它不像線寬那樣填滿。另外,您會注意到箭頭觸及D。怎麼把D往下推呢? (或者最好手動調整它?)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, trees, mindmap, calc}
\begin{document}
\begin{tikzpicture} 
\node (a) at (9,7.5) {};
\node (b) at (9,4.5) {B};
\node (c) at (10.5,6) {};
\node (d) at (7.5,6) {D};

\path[draw=black!60,solid,line width=0.8mm,fill=black!60,preaction={-triangle 90,thin,draw,shorten >=-1mm}] (a) -- (b);
\path[draw=black!60,solid,line width=0.8mm,fill=black!60,preaction={-triangle 90,thin,draw,shorten >=-1mm}] (c) -- (d);
\end{tikzpicture}
\end{document}

答案1

如果您將選項draw中的替換preaction為與行 ( fill=black!60) 所使用的樣式相同的樣式,您將獲得灰色箭頭(draw無論如何,都會從主操作繼承)。

您還可以縮短箭頭部分(以便它比實際線延伸得更遠)。我會恢復這個(因為它通常是由 PGF 完成的,當你將箭頭放在路徑),即實際線路被縮短,而箭頭則沒有。

我還定義了thicker line small arrows以 形式 接受其參數的樣式<line width> in <color>,可以重複使用該樣式以相同的方式設定各種線條的樣式。

我還提供了另一種使用庫放置箭頭thicker line small arrows m的方式(樣式) 。markings這不像通常的preaction/postaction方法那麼穩定,但是您無論如何都可以將箭頭放置在1in 的 路徑上at position 1

代碼1

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows}
\colorlet{mygray}{black!60}
\tikzset{thicker line small arrows/.style args={#1in#2}{
    draw=#2,
    solid,
    line width=#1,
    shorten >=1mm,
    preaction={
        fill=#2,
        thin,
        -triangle 90,
        shorten >=0mm,
    }
}}
\begin{document}
\begin{tikzpicture} 
\node (a) at (9,7.5) {};
\node (b) at (9,4.5) {B};
\node (c) at (10.5,6) {};
\node (d) at (7.5,6) {D};

\path[thicker line small arrows=.8mm in mygray] (a) -- (b);
\path[thicker line small arrows=.4mm in green] (c) -- (d);
\end{tikzpicture}
\end{document}

代碼2

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows, decorations.markings}
\colorlet{mygray}{black!60}
\tikzset{thicker line small arrows m/.style args={#1in#2}{
    draw=#2,
    solid,
    line width=#1,
    shorten >=1mm,
    decoration={
        markings,
        mark=at position 1.0 with {\arrow[fill=#2,thin]{triangle 90}}
    },
    postaction={decorate}
}}
\begin{document}    
\begin{tikzpicture} 
\node (a) at (9,7.5) {};
\node (b) at (9,4.5) {B};
\node (c) at (10.5,6) {};
\node (d) at (7.5,6) {D};

\path[thicker line small arrows m=.8mm in mygray] (a) -- (b);
\path[thicker line small arrows m=.4mm in green] (c) -- (d);
\end{tikzpicture}
\end{document}

輸出

在此輸入影像描述

相關內容