3

I am having difficulties writing a letter in a specific position in TikZ using the \node command.

This is the command that I am having difficulties with:

\node at (2,5) (nodeS) {S};

I found that this command was used to place letter here. When I run the command, however, I get this:

With text

This is what I had originally:

Without text

As you can see, there is a black dot that should not be there, and the graph is moved considerably. Furthermore, the 'S' moves with the graph when I change the coordinates of the \node command. Anyone know what is going wrong here?

This is the full code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}

\def\rowA{0,1,...,4}
\def\rowB{0,1,...,4}
\def\rowC{0,1,...,4}
\def\rowD{0,1,...,4}
\def\rowE{0,1,...,4}


\begin{document}

\begin{tikzpicture}[x=1.75cm,
                    y=1.75cm,
                    every node/.style={circle,
                                       inner sep=2pt,
                                       fill=black}
                   ]

  \foreach \x in \rowA { \node (A\x) at (\x,2)  {}; }
  \foreach \x in \rowB { \node (B\x) at (\x,1)    {}; }
  \foreach \x in \rowC { \node (C\x) at (\x,0)    {}; }
  \foreach \x in \rowD { \node (D\x) at (\x,-1)   {}; }
  \foreach \x in \rowE { \node (E\x) at (\x,-2)   {}; }

  \foreach \x/\y in {0/0,1/1,2/2,3/3,4/4} {\draw (A\x) -- (E\y) {};}

  \draw (A0) -- (A4);
  \draw (B0) -- (B4);
  \draw (C0) -- (C4);
  \draw (D0) -- (D4);
  \draw (E0) -- (E4);

  \draw (B0) -- (A1);
  \draw (C0) -- (A2);
  \draw (D0) -- (A3);
  \draw (E0) -- (A4);
  \draw (E1) -- (B4);
  \draw (E2) -- (C4);
  \draw (E3) -- (D4);

  \node at (2,5) (nodeS) {S};

\end{tikzpicture}
\end{document}
Surculus
  • 505
  • 6
    It seems to be because of your every node/.style command which also applies to your letter node and masks the letter. – Corentin Nov 05 '13 at 18:22
  • 6
    Well, you're defining every node/.style={circle, fill=black}. That also applies to the node containing the S, so you just end up with a large black circle. You can say \node [fill=none] at (2,5) (nodeS) {S}; to see the letter. I'm not sure what issue you're having with the placement, though: You're telling TikZ to place the S at the coordinate (2,5). The top row of your grid starts at (0,2), so the S is expected to be above the grid. Where do you want the S to go? – Jake Nov 05 '13 at 18:22
  • Ah, shamelessly copied the code did not notice the node/.style up there. How would I clear a style below a certain point, or for a certain vertex? Perhaps clearing the style will fix the odd positioning of the S. – Surculus Nov 05 '13 at 18:56
  • @Surculus: You can clear the style by saying \tikzset{every node/.style=}. But again: What do you mean by "odd positioning"? The S is exactly where you tell it to go. – Jake Nov 05 '13 at 18:59
  • @Jake: I want the S to be outside of the of the already drawn nodes. Whether it be north of it, south, east or west. However, if I change the coordinates of S, it always ends up in the the first C node (node 0,2 on the graph). – Surculus Nov 05 '13 at 19:04
  • I still don't understand. In your screenshot (and when I compile your document), the S node is north of the grid, at (2,5), not at (0,2). – Jake Nov 05 '13 at 19:08
  • Odd, I see the S differently on the screenshot. The black note is on the right spot, but the S is not. Here is a close screenshot of the S behind the node (0,2) of the graph: http://i.imgur.com/Zsi1vVh.png – Surculus Nov 05 '13 at 19:15
  • 1
    @Surculus: Aaah, now I see it in your screenshot. It doesn't appear when I compile your document, though. Are you using pdflatex or another compiler? – Jake Nov 05 '13 at 19:19
  • @Jake: Was using some build in compiler in auctex, an option called 'previed-latex'. I guess it does not handle TikZ very well. Worked perfectly using pdflatex. Thanks!

    By the way, how do I mark this answered when there are no 'answers'?

    – Surculus Nov 05 '13 at 19:32
  • @Surculus: Hm, weird, but glad it's solved now. I've turned my comment into an answer. – Jake Nov 05 '13 at 19:36

1 Answers1

3

you're defining every node/.style={circle, fill=black}. That also applies to the node containing the S, so you just end up with a large black circle. You can say \node [fill=none] at (2,5) (nodeS) {S}; to disable the filling for the S node, or you can reset the every node style by saying \tikzset{every node/.style=}.

The spurious S in your screenshot apparently is an artifact of the compiler you're using.

Jake
  • 232,450