Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My code here does what I would like, except some node outlines are dashed where they should be solid. I realise I am probably putting the dashed in the wrong place, but I just tried my way to this.

\tikzstyle{every node}=[circle, draw, fill=black!50, inner sep=0pt, minimum width=4pt]
\begin{tikzpicture}[thick,scale=0.8,->,shorten >=2pt]
    \draw (0,0) node {} -- (1,1) node {};
    \draw (1,1) node {} -- (2,1) node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw (0,2) node {} -- (1,1) [dashed] node {};
    \draw (1,2) node {} -- (2,1) [dashed] node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw (2,1) node {} -- (3,0) [dashed] node {};
    \draw (2,1) node {} -- (2,0) [dashed] node {};
    \draw (3,0) node {} -- (4,0) [dashed] node {};
    \draw (3,0) node {} -- (4,-1) [dashed] node {};
    \draw (1,1) node {} -- (1,0) [dashed] node {};
\end{tikzpicture}
share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

The dashed is in the right place, it applies to the whole draw command. It would probably make more sense semantically if you put it straight after \draw, but it doesn't have an effect on the output. The nodes are dashed because they're constructed as part of the dashed \draw command. To make the node borders unbroken, you can add solid to your every node style.

Here's your adapted code. Note that I've used the current syntax \tikzset{<style>/.style={<options>}}, which supersedes the \tikzstyle syntax.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\tikzset{
    every node/.style={
        circle,
        draw,
        solid,
        fill=black!50,
        inner sep=0pt,
        minimum width=4pt
    }
}
\begin{tikzpicture}[thick,scale=0.8,->,shorten >=2pt]
    \draw (0,0) node {} -- (1,1) node {};
    \draw (1,1) node {} -- (2,1) node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw  (0,2) node {} -- (1,1) node {};
    \draw (1,2) node {} -- (2,1) [dashed] node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw (2,1) node {} -- (3,0) [dashed] node {};
    \draw (2,1) node {} -- (2,0) [dashed] node {};
    \draw (3,0) node {} -- (4,0) [dashed] node {};
    \draw (3,0) node {} -- (4,-1) [dashed] node {};
    \draw (1,1) node {} -- (1,0) [dashed] node {};
\end{tikzpicture}

\end{document}
share|improve this answer
add comment

Jake's answer is correct but the way to draw this graph is not fine. First because we can avoid some code with style applied to some groups and I don't like the fact to (re)draw some nodes. It's possible without name the nodes to get the graph but we need to use shorten for <and >

1) we draw the nodes 2) we draw solid edges 3) we draw dashed edges

\documentclass{article}
\usepackage{tikz}

\begin{document}
\tikzset{
    every node/.style={
        circle,
        draw,
        %solid, no necessary now because the nodes are drawn first
        fill          = black!50,
        inner sep     = 0pt,
        minimum width =4 pt
    }   
}  

\begin{tikzpicture}[thick,scale=0.8,->,
                   shorten >=2pt+0.5*\pgflinewidth,
                   shorten <=2pt+0.5*\pgflinewidth,
                   every node/.style={circle,
                                      draw,
                                      fill          = black!50,
                                      inner sep     = 0pt,
                                      minimum width =4 pt}]
\path[draw] % we place the nodes once
       node at (0,0) {}  
       node at (1,1) {} 
       node at (2,1) {} 
       node at (3,2) {} 
       node at (4,1) {} 
       node at (3,0) {} 
       node at (2,0) {} 
       node at (4,0) {} 
       node at (4,-1){}
       node at (0,2) {} 
       node at (1,0) {} 
       node at (1,1) {} 
       node at (1,2) {} ; 

    \draw (0,0) -- (1,1) ; % it's possible because we use shorten at each side
    \draw (1,1) -- (2,1) ;
    \draw (2,1) -- (3,2) ;
    \draw (3,2) -- (4,1) ; 
    \draw (0,2) -- (1,1) ;

\begin{scope}   [dashed]  % now dashed is for the lines inside the scope
     \draw (1,2) -- (2,1)  ; 
     \draw (2,1) -- (3,0)  ;
     \draw (2,1) -- (2,0)  ;
     \draw (3,0) -- (4,0)  ;
     \draw (3,0) -- (4,-1) ;
     \draw (1,1) -- (1,0)  ; 
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.