4

This is my first time using TikZ. I can't figure out how to change the ordering of the nodes from bottom up starting from the bottom left corner?

Also, when I try to use package xcolor midnightblue doesn't work. Why is this? How can I get it to work?

\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
    Adding y=-1cm to the TikZ picture’s option would be one way. Or simply using \node [darkstyle] (\x\y) at (1.5*\x,-1.5*\y) {\label};} (note the -). — For future MWEs, please see Why not use the minimal class. – Qrrbrbirlbel Apr 05 '13 at 06:40
  • @Qrrbrbirlbel Man, this is really overwhelming... Does that mean it's not a good idea to use this code? – TheRealFakeNews Apr 05 '13 at 06:46
  • Other advice: instead of \x\y (Ex: 00, ..., 44), use a-\x-\y (ex: a-0-0, ..., a-4-4) to name your nodes. – Paul Gaborit Apr 05 '13 at 06:48
  • While the minimal class works quite good for simple TikZ pictures, it is not a class for minimal WEs. Simply use article or the standalone class (which, setup correctly, can automatically produce .png files). The [tag:standalone] class even has a tikz option which a) loads the tikz package automatically and b) crops the PDF so that you only have the picture. – Qrrbrbirlbel Apr 05 '13 at 06:50

1 Answers1

4

You need to use -y for the placement coordinate if you want to start at the bottom and work up. Also the color is MidnightBlue and it requires the use of the [dvipsnames] option:

enter image description here

Code:

\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}


If you desire the numbering to start at the bottom left and go up then you need to alter the computation of the \label:

enter image description here

Code:

\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}

Peter Grill
  • 223,288