12

I currently have the following code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=1]
\tikzstyle{every node}=[draw,shape=circle]
\path (0,0) node (p0) {$p_0$}
(-1.5,-1) node (p1) {$p_1$}
(-1.5,-2.5) node (p2) {$p_2$}
(1.5,-2.5) node (p3) {$p_3$}
(1.5,-1) node (p4) {$p_4$}
(0,-3.5) node (p5) { $p_5$};
\draw (p0) -- (p1)
(p0) -- (p1)
(p0) -- (p2)
(p0) -- (p3)
(p0) -- (p4)
(p0) -- (p5)
(p1) -- (p2)
(p1) -- (p3)
(p1) -- (p4)
(p1) -- (p5)
(p2) -- (p3)
(p2) -- (p4)
(p2) -- (p5)
(p3) -- (p4)
(p3) -- (p5)
(p4) -- (p5);
\end{tikzpicture}

\end{document}

but my problem is that this name each node. And i just want a simple dot. How do I do that?

cmhughes
  • 100,947
Andreas
  • 443
  • 2
  • 5
  • 7

3 Answers3

15

Personally in this case I prefer the syntax coordinate (p) at (x,y) (I know that it's the same things but I don't like {}.

Then the code can be :

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[dot/.style={draw,circle,minimum size=2mm,inner sep=0pt,outer sep=0pt,fill=blue}]
\path \foreach \x/\y [count=\k from 0] in { 0/0,  -1.5/-1, -1.5/-2.5,  1.5/-2.5, 1.5/-1,  0/-3.5}
         {coordinate [dot] (p\k) at (\x,\y)}; 
\draw \foreach \k [count=\j from 1] in {0,...,4}
         \foreach \kk  in {\j,...,5}  
            {(p\k)--(p\kk)};
\end{tikzpicture}

\end{document}

enter image description here

Alain Matthes
  • 95,075
10

If you remove the $p_1$,...,$p_6$ from your code then you obtain

enter image description here

On another note, have a look at

Is there something like \providetikzstyle similar to \providecommand?

which details that \tikzstyle isn't an ideal command to use. I've used an alternative in my code below.

\documentclass{article}

\usepackage{tikz}


\begin{document}
\begin{tikzpicture}[every node/.style={draw,shape=circle,fill=blue}]
\path (0,0) node (p0) {}
(-1.5,-1) node (p1) {}
(-1.5,-2.5) node (p2) {}
(1.5,-2.5) node (p3) {}
(1.5,-1) node (p4) {}
(0,-3.5) node (p5) { };
\draw (p0) -- (p1)
(p0) -- (p1)
(p0) -- (p2)
(p0) -- (p3)
(p0) -- (p4)
(p0) -- (p5)
(p1) -- (p2)
(p1) -- (p3)
(p1) -- (p4)
(p1) -- (p5)
(p2) -- (p3)
(p2) -- (p4)
(p2) -- (p5)
(p3) -- (p4)
(p3) -- (p5)
(p4) -- (p5);
\end{tikzpicture}


\end{document}
cmhughes
  • 100,947
  • yea thats it.. can you say anything about changing the node size? – Andreas Apr 24 '12 at 16:49
  • @Andreas is that part of your question? :) you can try for example minimum size=2cm – cmhughes Apr 24 '12 at 16:52
  • Its a follow up question i guess:) because I think the size of the nodes are to large.. and how would u use that size=2cm ? – Andreas Apr 24 '12 at 17:00
  • @Andreas no problem :) try ...,fill=blue,scale=0.5} for example. adjust as necessary – cmhughes Apr 24 '12 at 17:09
  • @Andreas: Use minimum size=<length> and inner sep=<length>. Both will make the node bigger than the included content. Then there is always the coordinate node type, i.e. use \coordinate instead of \node or \path .. coordinate .. instead of \path .. node ... These nodes have zero size, are not displayed at all and can't have any content. – Martin Scharrer Apr 24 '12 at 17:45
  • @cmhughes The figure does not match the code. \x and \y are exchanged. – Alain Matthes Apr 24 '12 at 19:34
5

You could also reduce your code a lot by using foreach loops. Also it's a good idea to specify parameters via macros, that way you can easily alter the look of your picture. In this example, the node size, node distance and node fillcolor can be changed by just changing the initial commands:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\pgfmathsetmacro{\minsize}{0.2cm}
\pgfmathsetmacro{\nodedist}{3}
\newcommand{\fillcolor}{black}


\begin{tikzpicture}[scale=1]
\tikzstyle{every node}=[draw,shape=circle,minimum size=\minsize,inner sep=0]
\foreach \x in {0,...,5}
    \node[fill=\fillcolor] (p\x) at (\x*60:\nodedist) {};
\foreach \x in {0,...,4}    
{   \pgfmathtruncatemacro{\startvalue}{\x+1}
    \foreach \y in {\startvalue,...,5}
    {\draw (p\x) -- (p\y);
    }
}
\end{tikzpicture}

\end{document}

enter image description here

Tom Bombadil
  • 40,123