我正在尝试使用 TikZ 绘制下图,但无法正确实现箭头。
B
我本质上可以拥有从节点到的箭头,A
但不是同一类型的从A
到的箭头B
。
有没有办法在 TikZ 中实现这一点?
逻辑是:
从节点A
到节点B
。连接箭头(导线)连接下一个B
,这里的下一个意味着,不仅在它们下面,而且在它们下面的旁边。每个下面A
有两个B
,但导线连接到下一个最近的B
. 左箭头有标签升(即左边)
从一个节点B
到另一个节点A
。连接箭头(电线)就在下方连接A
。
这是我的 MWE(感谢老合作者):
\documentclass[border=0.1mm]{standalone}
\usepackage{tikz}
\usepackage{scalerel}
\usepackage{ifthen}
\usetikzlibrary{decorations.markings}
%\usepackage[dvipsnames]{xcolor}
\colorlet{Mycolor1}{green!10!orange!70!}
\tikzset{
mynode/.style = {circle, draw, thick, fill=black, inner sep=0pt},
type1/.style = {mynode,black},
type2/.style = {mynode,Mycolor1},
}
\begin{document}
\begin{tikzpicture}[>=stealth]
\path[clip] (-3.1,-7.25) rectangle +(4.8,4.8);
\begin{scope}[rotate=45]
\foreach \x in {-8,...,0}
\foreach \y in {-9,...,0} {
\pgfmathsetmacro{\type}{int(mod(abs(\x+\y),2)+1)};
\draw[blue, -] (\x-0.6, \y) -- (\x+0.6, \y);
\ifthenelse{\type=1}{\node[black,below] at (\x-0.22, \y+0.27) {$\scaleto{l_{1}}{4.5pt}$};}{}
\ifthenelse{\type=2}{\node[black,below] at (\x-0.22, \y+0.27) {$\scaleto{l_{2}}{4.5pt}$};}{}
\draw[red, -] (\x, \y-0.6) -- (\x, \y+0.6);
\ifthenelse{\type=1}{\node[type\type] at (\x,\y) {\color{white}$A$};}{}
\ifthenelse{\type=2}{\node[type\type] at (\x,\y) {\color{black}$B$};}{}
}
\end{scope}
\end{tikzpicture}
\end{document}
B
这给了我们(我从步骤到有相同的接线连接,A
但没有从A
到B
):
编辑:经过一番努力,我可以获得第二步,即从步骤B
到A
。但失去了连接下方邻居的第一步,即从步骤A
到B
(在上述情况下存在)。此外,向左箭头的标签为 l(即左)
\begin{document}
\begin{tikzpicture}[>=stealth]
\path[clip] (-3.1,-7.25) rectangle +(4.8,4.8);
\begin{scope}[rotate=45]
\foreach \x in {-8,...,0}
\foreach \y in {-9,...,0} {
\pgfmathsetmacro{\type}{int(mod(abs(\x+\y),2)+1)};
\draw[blue, <-] (\x-0.8, \y+1) -- (\x+0.9, \y);
\ifthenelse{\type=1}{\node[black,below] at (\x-0.22, \y+0.27) {$\scaleto{l_{1}}{4.5pt}$};}{}
\ifthenelse{\type=2}{\node[black,below] at (\x-0.22, \y+0.27) {$\scaleto{l_{2}}{4.5pt}$};}{}
\draw[red, <-] (\x+1, \y-0.8) -- (\x, \y+0.9);
\ifthenelse{\type=1}{\node[type\type] at (\x,\y) {\color{white}$A$};}{}
\ifthenelse{\type=2}{\node[type\type] at (\x,\y) {\color{black}$B$};}{}
}
\end{scope}
\end{tikzpicture}
\end{document}
答案1
\documentclass[border=0.1mm]{standalone}
\usepackage{tikz}
\usepackage{scalerel}
\usepackage{ifthen}
\usetikzlibrary{decorations.markings}
%\usepackage[dvipsnames]{xcolor}
\colorlet{Mycolor1}{green!10!orange!70!}
\tikzset{
mynode/.style = {circle, draw, thick, fill=black, inner sep=0pt},
type1/.style = {mynode,black},
type2/.style = {mynode,Mycolor1},
}
\begin{document}
\begin{tikzpicture}[>=stealth]
\path[clip] (-3.1,-7.25) rectangle +(4.8,4.8);
\begin{scope}[rotate=45]
\foreach \x in {-8,...,0}
\foreach \y in {-9,...,0} {
\pgfmathsetmacro{\type}{int(mod(abs(\x+\y),2)+1)};
\draw[blue, <-] (\x-0.6, \y) -- (\x+0.6, \y);
\ifthenelse{\type=1}{\node[black,below] at (\x-0.22, \y+0.27) {$\scaleto{l_{1}}{4.5pt}$};}{}
\ifthenelse{\type=2}{\node[black,below] at (\x-0.22, \y+0.27) {$\scaleto{l_{2}}{4.5pt}$};}{}
\draw[red, <-] (\x, \y-0.6) -- (\x, \y+0.6);
\ifthenelse{\type=1}{\node[type\type] at (\x,\y) {\color{white}$A$};}{}
\ifthenelse{\type=2}{\node[type\type] at (\x,\y) {\color{black}$B$};}{}
}
\end{scope}
\end{tikzpicture}
\end{document}