我想我需要为这个箭头断裂定义一个不同的节点样式。
\documentclass[border=3cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows}
\begin{document}
\begin{tikzpicture}[auto, node distance = 5cm, thick,
every node/.style = {rectangle, minimum width= 30mm, rounded corners=20pt, font = \Large\sffamily, black,
top color = green!40!white, bottom color = green!20!white,drop shadow, minimum height = 2.5cm}]
\node (SWGDAM) {\textbf{SWGDAM}};
\node (42) [right = of SWGDAM] {4.2};
\draw [->] (SWGDAM) -- (42);
\end{tikzpicture}
\end{document}
答案1
这就是我要做的,重现该图像:
- 使用具有一些 RGB 定义的实际颜色。
- 使用该
arrows.meta
库。arrows
仍然受支持,但已被弃用。 - 我改变了节点中的一些样式,使其更加忠实于原图。另外,这只是个人喜好问题,但我建议不要使用粗体和大字体在一起。
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows.meta}
\definecolor{topgreen}{RGB}{242,255,225}
\definecolor{botgreen}{RGB}{220,253,174}
\definecolor{bordercol}{RGB}{158,174,125}
\definecolor{arrowcolor}{RGB}{74,126,186}
\tikzset{
box/.style={draw=bordercol, rectangle, font=\sffamily, top color=topgreen, bottom color=botgreen, drop shadow, minimum width=2cm, inner ysep=4pt},
myarr/.style={-{Straight Barb[angle=60:2pt 5]}, arrowcolor},
nodarr/.style={midway, fill=white, anchor=center, text=black, font=\sffamily}
}
\begin{document}
\begin{tikzpicture}[auto, node distance=4cm]
\node[box] (SWGDAM) {SWGDAM};
\node[box, right = of SWGDAM] (42) {4.2};
\draw[myarr] (SWGDAM) -- (42) node[nodarr] {TEXT};
\end{tikzpicture}
\end{document}
答案2
我猜,你想获得这样的东西:
\documentclass[border=3cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, shadows}
\begin{document}
\begin{tikzpicture}[
node distance = 5cm, thick,
every node/.style = {font = \Large\sffamily, text=black},
box/.style = {rectangle, draw=green,
minimum width= 30mm, minimum height = 12mm, %rounded corners=20pt,
top color = green!40!white, bottom color = green!20!white,
drop shadow}
]
\node (SWGDAM) [box] {SWGDAM};
\node (42) [box,right=of SWGDAM] {4.2};
\draw[->] (SWGDAM) -- node[fill=white] {TEXT} (42);
\end{tikzpicture}
\end{document}
因此,关于箭头中间的文本,你距离目标并不远,但你的节点样式是错误的。你需要两种不同的节点样式...
附录:
上述提议的变体。这次带有更花哨的箭头,箭头不再显示,而是显示文字。这样,您就可以使用不同的背景颜色(这在幻灯片演示中很方便,例如beamer
)。
\documentclass[border=3cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, shadows}
\begin{document}
\begin{tikzpicture}[
node distance = 5cm, thick,
every node/.style = {font = \Large\sffamily, text=black},
box/.style = {rectangle, draw=gray,
minimum width= 30mm, minimum height = 12mm,
top color = green!40!white, bottom color = green!20!white,
drop shadow},
txt/.style = {rectangle, inner ysep=1pt, fill=white, sloped},
arrow/.style = {draw=gray,line width=1mm, -{Triangle[]}},
]
\node (SWGDAM) [box] {SWGDAM};
\node (42) [box,right=of SWGDAM] {4.2};
\path (SWGDAM) to node[txt] (swg42) {TEXT} (42);
% real line with sloped text in the middle
\draw[arrow] (SWGDAM) -- (swg42) -- (42);
\end{tikzpicture}
\end{document}