我需要您的帮助才能在 tikz 中创建下图。我是 tikz 的初学者。
我在以下页面中看到了示例,但我需要如图所示的方式,而我无法制作 TikZ:使用循环绘制节点网格
答案1
也许这个代码可以帮到你。我们无法应用你链接中的代码,因为我们不知道箭头的位置是否是自动的。很大一部分需要手动绘制。下一个代码不是很优雅,但你可以尝试做得更好。一个好主意是在绘制网格之前用一个循环确定所有节点的坐标,就像在链接中一样,没有定义节点(只有坐标)。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
down/.style={path picture={
\draw[->] ([yshift=-3pt]path picture bounding box.north)
-- ([yshift=3pt]path picture bounding box.south);}},
up/.style={path picture={
\draw[->] ([yshift=3pt]path picture bounding box.south)
-- ([yshift=-3pt]path picture bounding box.north);}},
every node/.style={circle,draw, minimum size=1 cm}]
\node[label=45:$1$,up] (n-1-1) {};
\node[label=45:$2$,down] (n-1-2) at (2,0) {};
\node[label=45:$3$,up] (n-1-3) at (4,0) {};
\node[label=45:$n$,up] (n-1-4) at (6,0) {};
\node[label=45:$n+1$,down] (n-2-1) at (0,-2) {};
\node[label=45:$n+2$,up] (n-2-2) at (2,-2) {};
\node[label=45:$n+3$,down] (n-2-3) at (4,-2) {};
\node[label=45:$n+4$,up] (n-2-4) at (6,-2) {};
\node[up] (n-3-1) at (0,-4) {};
\node[up] (n-3-2) at (2,-4) {};
\node[down] (n-3-3) at (4,-4) {};
\node[down] (n-3-4) at (6,-4) {};
\node[up] (n-4-1) at (0,-6) {};
\node[down] (n-4-2) at (2,-6) {};
\node[up] (n-4-3) at (4,-6) {};
\node[down] (n-4-4) at (6,-6) {};
\foreach \i [count=\xi from 2] in {1,...,2}
\foreach \j [count=\xj from 2] in {1,...,3}
\draw (n-\i-\j) -- (n-\xi-\j);
\foreach \j [count=\xj from 2] in {1,...,4}
\draw[thick,dotted] (n-3-\j) -- (n-4-\j);
\foreach \i [count=\xi from 2] in {1,...,3}
\foreach \j [count=\xj from 2] in {1,...,2}
\draw (n-\i-\j) -- (n-\i-\xj);
\foreach \i [count=\xi from 2] in {1,...,4}
\draw[thick,dotted] (n-\i-3) -- (n-\i-4);
\draw (n-4-1) -- (n-4-2) (n-4-2)--(n-4-3) ;
\draw (n-1-4) -- (n-2-4) (n-2-4)--(n-3-4) ;
\foreach \i in {1,...,4} {%
\draw (n-\i-4)--++(1.5,0) ;
\draw (n-4-\i)--++(0,-1.5) ;
}
\end{tikzpicture}
\end{document}
做一些可能更好的事情。我删除了很大一部分代码。你现在的问题是绘制圆内的顶点和箭头。如果你想设计一些节点,我写了所有的标签来帮助你
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=10mm}]
\foreach \x in {0,...,4}
\foreach \y in {0,...,4}
{%\pgfmathtruncatemacro{\label}{\x - 5 * \y +21}
\node [darkstyle,label=45:$n-\x-\y)$] (n-\x-\y) at (2*\x,2*\y) {};}
% \foreach \x in {0,...,4}
% \foreach \y [count=\yi] in {0,...,3}
% \draw (n-\x-\y)--(n-\x-\yi) (n-\y-\x)--(n-\yi-\x) ;
\end{tikzpicture}
\end{document}