![tikz 图表中消失的箭头](https://linux22.com/image/467020/tikz%20%E5%9B%BE%E8%A1%A8%E4%B8%AD%E6%B6%88%E5%A4%B1%E7%9A%84%E7%AE%AD%E5%A4%B4.png)
我正在 tikz 中绘制有向无环图。它们看起来很棒,但是当我尝试指定箭头输入坐标时,箭头有时会消失,我想知道为什么。
我的序言是:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[landscape]{geometry}
\usepackage{float}
\usepackage{listings}
%load options
\usetikzlibrary{positioning, calc, shapes.geometric, shapes.multipart,
shapes, arrows.meta, arrows, decorations.markings, external, trees}
%Create custom arrow style:
\tikzstyle{Arrow} = [
thick,
decoration={
markings,
mark=at position 1 with {
\arrow[thick]{latex}
}
},
shorten >= 3pt, preaction = {decorate}
]
当我使用以下代码时,c-->Y 边缘上的所有箭头都会显示出来:
\begin{figure}[H]
\begin{tikzpicture}
\node (1) {};
\node [right =of 1] (2) {E};
\node [right =of 2] (3) {};
\node [right =of 3] (4) {Y};
\node [left =of 1] (5) {C};
\node [above =of 3] (6) {M};
\draw[Arrow] (2.east)--(4.west);
\draw[Arrow] (2) to (6);
\draw[Arrow] (6) to (4);
\draw[Arrow] (5) to [out=-25, in=-160] (4);
\draw[Arrow] (5) to (6);
\draw[Arrow] (5.east)--(2.west);
\end{tikzpicture}
\caption{}
\end{figure}
然而,当我改变时\draw[Arrow] (5) to [out=-25, in=-160]
箭头\draw[Arrow] (5) to [out=-25, in=-122]
消失了:
\begin{figure}[H]
\begin{tikzpicture}
\node (1) {};
\node [right =of 1] (2) {E};
\node [right =of 2] (3) {};
\node [right =of 3] (4) {Y};
\node [left =of 1] (5) {C};
\node [above =of 3] (6) {M};
\draw[Arrow] (2.east)--(4.west);
\draw[Arrow] (2) to (6);
\draw[Arrow] (6) to (4);
\draw[Arrow] (5) to [out=-25, in=-122] (4);
\draw[Arrow] (5) to (6);
\draw[Arrow] (5.east)--(2.west);
\end{tikzpicture}
\caption{}
\end{figure}
这只是我经常遇到的一个问题的简单示例,它让我无法精确控制更复杂的图表。有人能解释一下为什么会发生这种情况以及可能的解决方法吗?
答案1
我不会使用该markings
库,尤其是对于路径尖端的箭头。该库已内置于 PGF/TikZ 中,使用当前版本时有很多自定义选项arrows.meta
图书馆(与弃用的选项相比,它使用大写的箭头提示名称)。
只需简单操作,-Latex[scale=.8]
您就可以调整大小,使其看起来像您的输出,但实际上在末尾放置一个箭头,而无需猜测任何值。
tikzcd
我添加了由库提供的环境生成的相同图表cd
。它使用不同的节点间距离,但可以使用column sep
/row sep
和不同的s 进行调整。(不过,示例中没有inner sep
空节点1
和。)3
tikzcd
第一个图表还具有库提供的可选设置,cd
这对于具有不同高度和深度的更多不同内容的节点可能很有用。
对于弯曲路径,加载bending
库(已设置arrows=[flex]
)但arrows=[bend]
在这些路径上应用漂亮的箭头提示可能是一个好主意。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, cd, decorations.markings, positioning}
\begin{document}
\begin{tikzpicture}[
% this might be useful for more varied content:
% nodes=asymmetrical rectangle, commutative diagrams/center yshift=.75ex,
Arrow/.style={thick, -{Latex[scale=.8]}},
]
\node (1) {};
\node [right=of 1] (2) {E};
\node [right=of 2] (3) {};
\node [right=of 3] (4) {Y};
\node [left =of 1] (5) {C};
\node [above=of 3] (6) {M};
\path[Arrow] (2) edge (4) edge (6)
(6) edge (4)
(5) edge[out=-25, in=-122] (4)
edge (6) edge (2);
\end{tikzpicture}
\begin{tikzpicture}[Arrow/.style={
thick, shorten >= 3pt, preaction = decorate,
decoration={name=markings, mark=at position 1 with {\arrow[thick]{latex}}}}]
\node (1) {};
\node [right=of 1] (2) {E};
\node [right=of 2] (3) {};
\node [right=of 3] (4) {Y};
\node [left =of 1] (5) {C};
\node [above=of 3] (6) {M};
\draw[Arrow] (2.east)--(4.west);
\draw[Arrow] (2) to (6);
\draw[Arrow] (6) to (4);
\draw[Arrow] (5) to [out=-25, in=-122] (4);
\draw[Arrow] (5) to (6);
\draw[Arrow] (5.east)--(2.west);
\end{tikzpicture}
\begin{tikzcd}[
arrow style=tikz, >={Latex[scale=.8]},
arrows=thick, math mode=false, center yshift=+.75ex]
& & & M \ar[dr] \\
C \ar[rr] \ar[rrru] \ar[rrrr, out=-25, in=-122]
& & E \ar[ru] \ar[rr]
& & Y
\end{tikzcd}
\end{document}