![TikZ 图片箭头重叠](https://linux22.com/image/251870/TikZ%20%E5%9B%BE%E7%89%87%E7%AE%AD%E5%A4%B4%E9%87%8D%E5%8F%A0.png)
我想要这样的东西:
但是箭头在 TikZ 中重叠了!
我已经尝试了下面的代码,但是有没有比这更好的方法?
\documentclass{article}
\usepackage{color}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path (0,0) node(a) [rectangle,draw, fill=blue, text=white] {\LARGE EP};
\path (2,3) node(b) [rectangle,draw, fill=Cyan] {\LARGE GK};
\path (7,3) node(c) [rectangle,draw, fill=Cyan] {\LARGE GK};
\path (9,0) node(d) [rectangle,draw, fill=blue, text=white] {\LARGE EP};
\draw[thick,<-] (a.north) -- (b.west) node[midway, below right=0.3cm]{\parbox{2cm}{1. Request permission to place call}};
\draw[thick,->] (a.east) -- (b.south) node[midway, above left=0.3cm]{\parbox{2cm}{4. Grant permission to place call}};
\end{tikzpicture}
\end{document}
答案1
我的回答(根据问题中的图片)是:
以下是代码:
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\tikzset{block/.style={rectangle,draw,minimum height=1cm,minimum width=1cm}}
\begin{document}
\begin{tikzpicture}
\path (0,0) node(a) [block, fill=blue, text=white] {\LARGE EP};
\path (2.5,3) node(b) [block, fill=Cyan] {\LARGE GK};
\path (6.5,3) node(c) [block, fill=Cyan] {\LARGE GK};
\path (9,0) node(d) [block, fill=blue, text=white] {\LARGE EP};
\draw[thick,stealth-] (a.120) -- (b.150) node[midway, below right=0.4cm,text width=1.75cm ]{1. Request permission to place call};
\draw[thick,-stealth] (a.70) -- (b.210) node[pos= 0.3, above left,text width=1.75cm]{4. Grant permission to place call};
\end{tikzpicture}
\end{document}
我创建了一个名为的样式,block
其中还定义了minimum width
和minimum height
。此外,为了设置箭头的起点和终点,我使用了方框的角度,而不是采用parbox
es,我更喜欢设置text width
选项。
答案2
我删除color
,因为xcolor
加载color
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node [draw, fill=blue, text=white,minimum size=24pt,outer sep=2pt] (a) at (0,0) {\LARGE EP};
\node [draw, fill=Cyan,minimum size=24pt,outer sep=2pt] (b) at (3,2) {\LARGE GK};
\draw[thick,->] ([xshift=-6pt]a.north) -- ([yshift=+4pt]b.west)
node[midway, below right=5pt,align=left,font=\small]
{1. Request \\permission \\to place call};
\draw[thick,<-] ([xshift=+6pt]a.north) -- ([yshift=-4pt]b.west)
node[midway, above left=5pt,align=left,font=\small]
{4. Grant \\ permission\\ to place call};
\end{tikzpicture}
\end{document}