![如何在 tikz 中的节点之间绘制括号](https://linux22.com/image/352529/%E5%A6%82%E4%BD%95%E5%9C%A8%20tikz%20%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9%E4%B9%8B%E9%97%B4%E7%BB%98%E5%88%B6%E6%8B%AC%E5%8F%B7.png)
我有三个盒子。它们位于节点中。我想在它们之间建立如下连接:
\node[cubecontainer] (a) at (0,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=A, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (b) at (4,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=B, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (c) at (8,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=C, width=6, height=20, depth=15, units=mm}};
我怎样才能使蓝色箭头和红色括号连接它们。我生成三个框的完整代码是
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{quotes,arrows.meta}
\tikzset{
annotated cuboid/.pic={
\tikzset{%
every edge quotes/.append style={midway, auto},
/cuboid/.cd,
#1
}
\draw [\cubeline,every edge/.append style={pic actions, \cubeback, opacity=.5}, pic actions]
(0,0,0) coordinate (o-\cubelabel) -- ++(-\cubescale*\cubex,0,0) coordinate (a-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (b-\cubelabel) edge coordinate [pos=1] (g-\cubelabel) ++(0,0,-\cubescale*\cubez) -- ++(\cubescale*\cubex,0,0) coordinate (c-\cubelabel) -- cycle
(o-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (d-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (e-\cubelabel) edge (g-\cubelabel) -- (c-\cubelabel) -- cycle
(o-\cubelabel) -- (a-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (f-\cubelabel) edge (g-\cubelabel) -- (d-\cubelabel) -- cycle;
;
},
/cuboid/.search also={/tikz},
/cuboid/.cd,
width/.store in=\cubex,
height/.store in=\cubey,
depth/.store in=\cubez,
units/.store in=\cubeunits,
scale/.store in=\cubescale,
label/.store in=\cubelabel,
line/.store in=\cubeline,
backline/.store in=\cubeback,
width=10,
height=10,
depth=10,
units=cm,
scale=.1,
line=draw,
backline=densely dashed,
}
\newcommand{\cuboid}[2]{
\begin{tikzpicture}
\pic [#1] at (0,0) {annotated cuboid={#2}};
\end{tikzpicture}
}
\tikzstyle{cubecontainer}=[outer sep = 0pt, inner sep= 0pt]
\tikzstyle{connectarrow}=[-{Triangle[angle=60:0pt 2]},
line width= 10pt, shorten >=3mm,shorten <=3mm, draw=gray!60]
\begin{document}
\begin{tikzpicture}
\node[cubecontainer] (a) at (0,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=A, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (b) at (4,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=B, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (c) at (8,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=C, width=6, height=20, depth=15, units=mm}};
\end{tikzpicture}
\end{document}
答案1
您可以像任何其他路径一样绘制箭头,并且使用decorations.pathreplacing
库完成括号。
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{quotes,arrows.meta, decorations.pathreplacing}
\tikzset{
annotated cuboid/.pic={
\tikzset{%
every edge quotes/.append style={midway, auto},
/cuboid/.cd,
#1
}
\draw [\cubeline,every edge/.append style={pic actions, \cubeback, opacity=.5}, pic actions]
(0,0,0) coordinate (o-\cubelabel) -- ++(-\cubescale*\cubex,0,0) coordinate (a-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (b-\cubelabel) edge coordinate [pos=1] (g-\cubelabel) ++(0,0,-\cubescale*\cubez) -- ++(\cubescale*\cubex,0,0) coordinate (c-\cubelabel) -- cycle
(o-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (d-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (e-\cubelabel) edge (g-\cubelabel) -- (c-\cubelabel) -- cycle
(o-\cubelabel) -- (a-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (f-\cubelabel) edge (g-\cubelabel) -- (d-\cubelabel) -- cycle;
;
},
/cuboid/.search also={/tikz},
/cuboid/.cd,
width/.store in=\cubex,
height/.store in=\cubey,
depth/.store in=\cubez,
units/.store in=\cubeunits,
scale/.store in=\cubescale,
label/.store in=\cubelabel,
line/.store in=\cubeline,
backline/.store in=\cubeback,
width=10,
height=10,
depth=10,
units=cm,
scale=.1,
line=draw,
backline=densely dashed,
}
\newcommand{\cuboid}[2]{
\begin{tikzpicture}
\pic [#1] at (0,0) {annotated cuboid={#2}};
\end{tikzpicture}
}
\tikzstyle{cubecontainer}=[outer sep = 0pt, inner sep= 0pt]
\tikzstyle{connectarrow}=[-{Triangle[angle=60:0pt 2]},
line width= 10pt, shorten >=3mm,shorten <=3mm, draw=gray!60]
\begin{document}
\begin{tikzpicture}
\node[cubecontainer] (a) at (0,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=A, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (b) at (4,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=B, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (c) at (8,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
{label=C, width=6, height=20, depth=15, units=mm}};
\draw[line width=2mm, green, -latex, shorten >=1mm, shorten <=1mm] (a.north) --++(90:1cm)-|(c.north);
\draw[ultra thick, red, decoration={brace, raise=5pt, mirror, amplitude=3mm}, decorate] (a.south west) -- (c.south east);
\draw[line width=2mm, green, -latex, shorten >=1mm, shorten <=1mm] ([yshift=-5mm]b.south)--++(-90:1.5cm);
\end{tikzpicture}
\end{document}