换句话说,我需要所有盒子都是相同的形状(正方形或矩形),并且所有电线都像第二张图中的一样细。电线的标签不是必需的。在 tikz 中,最有效的方法是什么?
第二张图片的代码是
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,positioning}
\newcommand{\catname}[1]{\mathbf{#1}}
\begin{document}
\begin{tikzpicture}[arr/.style={
postaction={decorate},
decoration={
markings,
mark=at position #1 with {\arrow{>}}}}]
\node at (0,0) [rectangle, draw, minimum size= 10 mm] (f) {\emph{John}};
\node at (0,2) [rectangle] (h) {};
\draw[arr=0.6] (0, 0.5) -- (0, 1.5) node[pos=0.3,right]{$\catname{n_m}$};
\draw (0,1.5) to[out=90,in=90,looseness=2] (1,1.5);
\draw[arr=0.5] (1,1.5) -- (1,0.5)node[pos=0.6,right]{$\catname{n^r}$};
\node at (1.5,0) [rectangle, draw, minimum size= 10 mm] (f) {\emph{likes}};
\node at (3,2) [rectangle] (h) {};
\draw [->] (1.6,0.5) -- (1.6,2) node[above, left] {$\catname{s_1}$};
\draw[arr=0.6] (2, 1.5) -- (2, 0.5) node[pos=0.6,right]{$\catname{n^l}$};
\draw (2,1.5) to[out=90,in=90,looseness=2] (3,1.5);
\draw[arr=0.5] (3,0.5) -- (3,1.5)node[pos=0.4,right]{$\catname{n^f}$};
\node at (3,0) [rectangle, draw, minimum size= 10 mm] (f) {\emph{Mary}};
\end{tikzpicture}
\end{document}
我想重现第一张图片,我认为我可以使用与第二张图片类似的技术。但是,我发现最困难的是绘制第一个标有 $\nu$ 的三角形后面的两个圆弧,我无法将它们一个放在另一个上面。有什么提示吗?
答案1
连接 $\nu$ 和 $\Psi$ 的导线如此曲折,有什么特殊原因吗?如果你正在考虑同位素的弦图,你可以通过以下方式“拉直”所有导线来大大简化绘图:
\documentclass[margin=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,positioning}
\newcommand{\catname}[1]{\mathbf{#1}}
\begin{document}
\tikzset{
arr/.style={ postaction={decorate}
, decoration={ markings
, mark=at position #1 with {\arrow{>}}
}
},
arr/.default=0.5,
rarr/.style 2 args={ rounded corners= #1
, postaction={decorate}
, decoration={ markings
, mark=at position #2 with {\arrow{>}}
}
},
% the `rarr` style adds an argument for the roundedness of the corners
% `rarr` defaults at {4mm}{0.5}, and `arr` at 0.5:
rarr/.default={4mm}{0.5},
leaf/.style={ rectangle
, draw
%==
, thick
, fill=gray!10
%== improves readability
, minimum size= 10 mm
},
}
\begin{tikzpicture}
\node[leaf] (nu) at (0,0) {$\nu$};
% ...is this a \nu or a `v`? Considering that the other is a `w`...
% anyway, first draw all the nodes:
\node[leaf] (not) at (4,0) {\emph{not}};
\node[leaf] (psi) at (6,0) {$\Psi$};
\node[leaf] (w) at (8,0) {$w$};
% now the wires:
\draw[rarr] (psi.-50)
% ↑
% note that the starting point of the wire is at -45 degress \pm an offset;
% in this case, 5 degrees. Same for the left wire exiting from \Psi.
|- ++(1.5,-.5)
-- (w.south);
\draw[rarr] (psi.south)
|- ++(-2,-.5)
-- (not.south);
\draw[rarr={2mm}{0.75}] (psi.-130)
% here's where the possibility to adjust `rarr` first parameter comes in handy.
|- ++(-.5,-.25)
-- ++(-.05, 3)
-| (2,-1)
-- (0,-1)
-- (nu.south);
\draw[rarr={1mm}{.75}] (not.north)
|- ++(-1,1)
-| ++(-.25,-3);
\end{tikzpicture}
\end{document}