这是我第一次使用 TikZ。我不知道如何从左下角开始从下往上更改节点的顺序?
另外,当我尝试使用软件包xcolor
midnightblue 时,它不起作用。这是为什么?我该如何让它工作?
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[darkstyle/.style={circle,draw,fill=midnightblue!25,minimum size=4}]
\foreach \x in {0,...,4}
\foreach \y in {0,...,4}
{\pgfmathtruncatemacro{\label}{\x - 5 * \y +21}
\node [darkstyle] (\x\y) at (1.5*\x,1.5*\y) {\label};}
\foreach \x in {0,...,4}
\foreach \y [count=\yi] in {0,...,3}
\draw (\x\y)--(\x\yi) (\y\x)--(\yi\x) ;
\end{tikzpicture}
\end{document}
答案1
-y
如果您想从底部开始向上工作,则需要使用放置坐标。颜色也是MidnightBlue
,它需要使用以下[dvipsnames]
选项:
代码:
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[darkstyle/.style={circle,draw,fill=MidnightBlue!25,minimum size=4}]
\foreach \x in {0,...,4}
\foreach \y in {0,...,4}
{\pgfmathtruncatemacro{\label}{\x - 5 * \y +21}
\node [darkstyle] (\x\y) at (1.5*\x,-1.5*\y) {\label};}
\foreach \x in {0,...,4}
\foreach \y [count=\yi] in {0,...,3}
\draw (\x\y)--(\x\yi) (\y\x)--(\yi\x) ;
\end{tikzpicture}
\end{document}
如果您希望编号从左下角开始向上,那么您需要改变计算方式\label
:
代码:
\RequirePackage[dvipsnames]{xcolor}
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[darkstyle/.style={circle,draw,fill=MidnightBlue!25,minimum size=4}]
\foreach \x in {0,...,4}
\foreach \y in {0,...,4}
{\pgfmathtruncatemacro{\label}{5*\x + \y + 1}
\node [thick, darkstyle, minimum size=2.5em] (\x\y) at (1.5*\x,1.5*\y) {\label};}
\foreach \x in {0,...,4}
\foreach \y [count=\yi] in {0,...,3}
\draw (\x\y)--(\x\yi) (\y\x)--(\yi\x) ;
\end{tikzpicture}
\end{document}