使用兩種不同的顏色填滿箭頭尖端而不是路徑

使用兩種不同的顏色填滿箭頭尖端而不是路徑

我的一些箭頭有一個小問題,但我似乎找不到解決方案。請注意,這個問題不同於僅設定 TikZ 箭頭提示的填滿顏色(而非路徑本身),因為OP的意思是讓整個箭頭變成一種顏色。

如果我希望箭頭尖端為黑色,箭頭路徑為彩色,我會簡單地說, draw=black但我需要相反的,一條帶有彩色尖端的黑色路徑。

這就是我得到的:

在此輸入影像描述

這是我的程式碼:

\documentclass[10pt]{article}
\usepackage[a4paper, margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}

\usetikzlibrary{arrows,backgrounds,decorations,shapes,shapes.multipart,positioning}
\pgfplotsset{compat=1.7}

\begin{document}

    \definecolor{blue}{RGB}{0,127,255}

    \tikzset{
    opera/.style={fill=white, inner sep=0pt, right=3mm, text width= 5cm,font=\footnotesize},
    tear/.style={draw=black, fill=blue, -*},.
    }

    \begin{tikzpicture}

\draw[tear] (12, 5) -- (12,4) -- (10,3) -- (10,2) node[opera] at (10,2){Not the path!};

   \end{tikzpicture}
\end{document}

我已嘗試刪除盡可能多的內容以使程式碼最少,因此如果您看到未使用的套件或庫,請不要擔心。

我認為添加選項是一種可能的解決方案,但嘗試使用或箭頭提示>=stealth設定顏色。沒有一個起作用。o*

答案1

以下答案基於markingspostaction

\documentclass[10pt]{article}
\usepackage[a4paper, margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}

\usetikzlibrary{arrows,backgrounds,decorations.markings,shapes,shapes.multipart,positioning}
\pgfplotsset{compat=1.7}

\begin{document}

    \definecolor{blue}{RGB}{0,127,255}

    \tikzset{
    opera/.style={fill=white, inner sep=0pt, right=3mm, text width= 5cm,font=\footnotesize},
    tear/.style={draw=black,-, 
    decoration={markings,mark=at position 1 with {\arrow[draw=black,fill=blue]{*}}},
    postaction=decorate},.
    }

    \begin{tikzpicture}

\draw[tear] (12, 5) -- (12,4) -- (10,3) -- (10,2);

   \end{tikzpicture}
\end{document}

其產生:
在此輸入影像描述

我從您的樣式中刪除了箭頭tear並添加了decoration={markings,mark=at position 1 with {\arrow[draw=black,fill=blue]{*}}}postaction=decorate。透過這種方式,箭頭將被繪製為段末尾的裝飾,而不填充路徑。您還需要將裝飾載入為postactionwith postaction=decorate,以便僅覆蓋箭頭而不是整行。


編輯:以前的方法現在(隨著 PGF 3.0.0 的發布)已經過時:

\documentclass{standalone}
\usepackage{tikz}
    \usetikzlibrary{arrows.meta}
    \definecolor{myblue}{RGB}{0,127,255}

    \tikzset{
        opera/.style={
            fill=white,
            inner sep=0pt,
            right=3mm,
            text width= 5cm,
            font=\footnotesize
        },
        tear/.style={
            -{Circle[fill=myblue]}      %new code, requires arrows.meta and at least PGF 3.0.0
        },
     }
\begin{document}
\begin{tikzpicture}
    \draw[tear] (12, 5) -- (12,4) -- (10,3) -- (10,2) node[opera] {Not the path!};
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容