
Как мне исправить цвет в наконечнике стрелки? Он не заполняется так, как ширина линии. Кроме того, вы заметите, что стрелка касается 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
, но вы можете разместить стрелку в любом случае на пути с помощью 1
in 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}