我如何在 LaTeX 中输入以下图表(也许 Ti钾Z)?:我想要 10 个要点,按 5 乘 5 矩阵下三角部分的点排列。然后我想要从每个节点指向其正上方节点的箭头。提前致谢!
答案1
像这样?
\documentclass[tikz, border=1cm]{standalone}
\newlength\radius
\setlength\radius{2pt}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0,...,4}{ % rows
\foreach \j in {0,...,4}{ % columns
\ifnum\numexpr\j-\i<0\relax % check for lower triangle
\def\fill{fill}
\else
\def\fill{}
\fi
\draw[\fill] (\j, -\i) circle (\radius);
\ifnum\i>0\relax % if not in first row, draw arrow
\draw[->, blue, shorten <=\radius, shorten >=\radius] (\j, -\i) -- +(0,1);
\fi
}
}
\end{tikzpicture}
\end{document}
删除白点后的代码。
\documentclass[tikz, border=1cm]{standalone}
\newlength\radius
\setlength\radius{2pt}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0,...,4}{ % rows
\foreach \j in {0,...,4}{ % columns
\ifnum\numexpr\j-\i<0\relax % check for lower triangle
\filldraw (\j, -\i) circle (\radius);
\ifnum\i>0\relax % if not in first row, draw arrow
\draw[->, blue, shorten <=\radius, shorten >=\radius] (\j, -\i) -- +(0,1);
\fi
\fi
}
}
\end{tikzpicture}
\end{document}
答案2
Οὖτις 的漂亮答案的一个变体,使用node
s 而不是circle
s 来简化绘制箭头:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \i [evaluate=\i as \u using int(\i-1)] in {0,...,3}{
\foreach \j [evaluate=\j as \v using int(\j-\i)] in {\i,...,3}{
\node[circle, fill, inner sep=2pt] at (\v, \i) (n-\v-\i) {};
\ifnum\i>0\relax
\draw[->, blue] (n-\v-\u) -- (n-\v-\i);
\fi
}
}
\end{tikzpicture}
\end{document}