![使用括号和箭头连接范围](https://linux22.com/image/307418/%E4%BD%BF%E7%94%A8%E6%8B%AC%E5%8F%B7%E5%92%8C%E7%AE%AD%E5%A4%B4%E8%BF%9E%E6%8E%A5%E8%8C%83%E5%9B%B4.png)
我正在处理一个 tikz 图形,到目前为止它是这样的:
使用以下代码生成:
\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{matrix, calc, backgrounds, decorations.pathreplacing}
\begin{document}
\tikzset{
blur/.style={preaction={draw,fill,white,opacity=.9,line width=2pt}},
showdepth/.style={color=#1,ball color=#1,opacity=1+(\k-2)/5},
edgemeta/.is choice,
edgemeta/1/.style={blur,showdepth=green},
edgemeta/2/.style={blur,showdepth=yellow},
nodemeta/.is choice,
nodemeta/0/.style={blur,showdepth=blue},
nodemeta/1/.style={blur,showdepth=green},
nodemeta/2/.style={blur,showdepth=yellow},
drawedge_i/.style={drawedgex_i,drawedgey_i,drawedgez_i},
% Input volume
drawedgex_i/.code={
\ifnum\i=2\else
\pgfmathparse{int(max(abs(\i),abs(\i+1),abs(\j),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(1,0,0);
\fi
},
drawedgey_i/.code={
\ifnum\j=2\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\j+1),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,1,0);
\fi
},
drawedgez_i/.code={
\ifnum\k=2\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\k),abs(\k+1)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,0,1);
\fi
},
% Sublume
drawedge_s/.style={drawedgex_s,drawedgey_s,drawedgez_s},
drawedgex_s/.code={
\ifnum\i=1\else
\pgfmathparse{int(max(abs(\i),abs(\i+1),abs(\j),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(1,0,0);
\fi
},
drawedgey_s/.code={
\ifnum\j=1\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\j+1),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,1,0);
\fi
},
drawedgez_s/.code={
\ifnum\k=1\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\k),abs(\k+1)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,0,1);
\fi
},
% Node
drawnode/.code={
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\k)))}
\shade[nodemeta=\pgfmathresult](\i,\j,\k)circle(3pt);
}
}
\begin{tikzpicture}[z={(-.3,-.15)},draw=white,decoration={brace,amplitude=10}]
\begin{scope}
\foreach\k in{-2,...,2}{
\foreach\j in{-2,...,2}{
\foreach\i in{-2,...,2}{
\path[drawedge_i,drawnode];
}
}
}
\coordinate (A) at (1,1,0); \coordinate (B) at (1,-1,0);
\draw [decorate, red, thick] (A.north east) -- (B.south east);
\end{scope}
\begin{scope}[xshift=5cm]
\foreach\k in{-1,...,1}{
\foreach\j in{-1,...,1}{
\foreach\i in{-1,...,1}{
\path[drawedge_s,drawnode];
}
}
}
\end{scope}
\begin{scope}[xshift=9cm]
\foreach\k in{-1,...,1}{
\foreach\j in{-1,...,1}{
\foreach\i in{-1,...,1}{
\path[drawedge_s,drawnode];
}
}
}
\end{scope}
\end{tikzpicture}
\end{document}
我想知道如何改变括号的“宽度”以使其到达第二张图像,或者如何从中绘制箭头来连接这些范围,如下所示:
另外,我想知道如何使用箭头连接到范围,例如:
在此图像中,我使用了\matrix(name)
,因此我可以简单地执行:
\draw [red, -latex, thick](A) -- (B)
例如。
使用范围,我尝试执行以下操作:
\begin{scope}[name=A]
\end{scope}
\begin{scope}[name=B]
\end{scope}
\draw [red, -latex, thick](A) -- (B)
但我收到一条错误,警告我未找到具有该名称的形状。
先感谢您。
答案1
您已经学会了如何node
在绘制括号时定义 s。再定义一些 s 并绘制。
\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{matrix, calc, backgrounds, decorations.pathreplacing}
\begin{document}
\tikzset{
blur/.style={preaction={draw,fill,white,opacity=.9,line width=2pt}},
showdepth/.style={color=#1,ball color=#1,opacity=1+(\k-2)/5},
edgemeta/.is choice,
edgemeta/1/.style={blur,showdepth=green},
edgemeta/2/.style={blur,showdepth=yellow},
nodemeta/.is choice,
nodemeta/0/.style={blur,showdepth=blue},
nodemeta/1/.style={blur,showdepth=green},
nodemeta/2/.style={blur,showdepth=yellow},
drawedge_i/.style={drawedgex_i,drawedgey_i,drawedgez_i},
% Input volume
drawedgex_i/.code={
\ifnum\i=2\else
\pgfmathparse{int(max(abs(\i),abs(\i+1),abs(\j),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(1,0,0);
\fi
},
drawedgey_i/.code={
\ifnum\j=2\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\j+1),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,1,0);
\fi
},
drawedgez_i/.code={
\ifnum\k=2\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\k),abs(\k+1)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,0,1);
\fi
},
% Sublume
drawedge_s/.style={drawedgex_s,drawedgey_s,drawedgez_s},
drawedgex_s/.code={
\ifnum\i=1\else
\pgfmathparse{int(max(abs(\i),abs(\i+1),abs(\j),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(1,0,0);
\fi
},
drawedgey_s/.code={
\ifnum\j=1\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\j+1),abs(\k)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,1,0);
\fi
},
drawedgez_s/.code={
\ifnum\k=1\else
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\k),abs(\k+1)))}
\draw[edgemeta=\pgfmathresult](\i,\j,\k)--+(0,0,1);
\fi
},
% Node
drawnode/.code={
\pgfmathparse{int(max(abs(\i),abs(\j),abs(\k)))}
\shade[nodemeta=\pgfmathresult](\i,\j,\k)circle(3pt);
},
mydeco/.style={decoration={brace,amplitude=#1},decorate}
}
\begin{tikzpicture}[z={(-.3,-.15)},draw=white]
\begin{scope}
\foreach\k in{-2,...,2}{
\foreach\j in{-2,...,2}{
\foreach\i in{-2,...,2}{
\path[drawedge_i,drawnode];
}
}
}
\coordinate (A) at (1,1,0); \coordinate (B) at (1,-1,0);
\draw [mydeco={10}, red, thick] (A.north east) -- (B.south east)node[coordinate,midway,right](C){};
\end{scope}
\begin{scope}[xshift=5cm]
\foreach\k in{-1,...,1}{
\foreach\j in{-1,...,1}{
\foreach\i in{-1,...,1}{
\path[drawedge_s,drawnode];
}
}
}
\coordinate (D) at (-1,0,0);
\draw[red,-latex,shorten >= 5pt,shorten <= 10pt] (C) -- (D);
\coordinate (E) at (1,1,0); \coordinate (F) at (1,-1,0);
\draw [mydeco={10}, red, thick] (E.north east) -- (F.south east)node[coordinate,midway,right](G){};
\end{scope}
\begin{scope}[xshift=9cm]
\foreach\k in{-1,...,1}{
\foreach\j in{-1,...,1}{
\foreach\i in{-1,...,1}{
\path[drawedge_s,drawnode];
}
}
}
\coordinate (H) at (-1,0,0);
\draw[red,-latex,shorten >= 5pt,shorten <= 10pt] (G) -- (H);
\end{scope}
\end{tikzpicture}
\end{document}
只要确保尺寸(此处为 10)mydeco={10}
和shorten <= 10pt
相同即可。