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.

Based on a previously asked question by me I already have the following code:

\documentclass [11pt,a4paper] {article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{amsmath,tikz}
\usepackage[margin=1cm]{geometry}
\usepackage{collcell}
\usetikzlibrary{patterns,matrix,arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
  thick,main node/.style={circle,fill=RoyalBlue!90!green!80,draw,font=\sffamily\Large\bfseries}]
  \node[main node] [label=above:Cause](1) {Y};
  \node[main node] [label=above:Effect](2) [right of=1] {$X$};
  \node[main node] [](3)[above=1] {$N_X$};
  \node[main node] [](4)[above=2] {$N_Y$};

  \path[every node/.style={font=\sffamily\small}]
    (1)edge [right] node[below right] {$\varphi$} (2);
  \path[every node/.style={font=\sffamily\small, color=orange}]
    (2)edge[bend right,color=orange]node[above] {$\varphi^{-1}$} (1);
  \path[every node/.style={font=\sffamily\small, color=orange}]
    (3)edge[color=red]node[below] {id} (1);
  \path[every node/.style={font=\sffamily\small, color=orange}]
    (4)edge[color=blue]node[below] {} (2);
\end{tikzpicture}
\end{document}

However I want to be able to add two nodes without borders as depicted in the following diagram to my diagram:

enter image description here

As you probably figured it by now, I don't know why but my code puts the circles above each other though I positioned them(3 and 4) relative to two different nodes(1 and 2). and also I don't know how to make the circles disappear and to only keep labels. I have to add that I am happy with the connections between nodes 1 and 2 and the colors of them. I only need the new connections and nodes.

share|improve this question
    
But they are still filled. plus the positions are not correct! –  Naji May 3 '13 at 18:11
add comment

3 Answers

up vote 7 down vote accepted

I don't understand what should happen here but you should not use numbers as node names. That's why above=1 didn't give you any errors because it automatically assumes it 1cm and draws nonsense. There are many strange syntax used in the MWE so here is a little bit tidied up version but still I don't know what the goal is.

\PassOptionsToPackage{usenames,dvipsnames,svgnames,table}{xcolor}
\documentclass [11pt,a4paper] {article}
\usepackage{amsmath,tikz}

\usetikzlibrary{patterns,matrix,arrows}
\begin{document}
\begin{tikzpicture}[->,
  >=stealth',
  shorten >=1pt,
  auto,
  node distance=3cm,
  thick,
  main node/.style={
              circle,
              fill=RoyalBlue!90!green!80,
              draw,
              font=\sffamily\Large\bfseries}
 ]
  \node[main node,label=above:Cause]             (y)  {Y};
  \node[main node,label=above:Effect,right of=y] (x)  {$X$};
  \node[below of=x]                              (nx) {$N_X$};
  \node[below of=y]                              (ny) {$N_Y$};

  \path (y)  edge[right] node[below right,font=\sffamily\small] {$\varphi$} (x);
  \path (x)  edge[bend right,orange]node[above,font=\sffamily\small,orange]{$\varphi^{-1}$}(y);
  \path (nx) edge[red] node[left,font=\sffamily\small,orange] {id} (x);
  \path (ny) edge[blue] (y);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
I didn't know of that autocorrection!! –  Naji May 3 '13 at 18:29
    
Good point about nodes named as numbers. –  Matthew Leingang May 3 '13 at 18:30
    
@percusse I do have a problem. As I can see node distances are not part of the style. How should I decrease the lenght of edges from N_X and N_Y comparing to the one between X and Y? –  Naji May 3 '13 at 18:37
1  
@Naji: You can also use below=<dimen> of 1 to make the separation anything you want. –  Matthew Leingang May 3 '13 at 18:40
1  
@Naji What Matthew said. Also have a look at this before going deeper about positioning library syntax difference tex.stackexchange.com/questions/9386/… –  percusse May 3 '13 at 18:43
add comment

If you don't want nodes 3 and 4 to be styled the same way as 1 and 2 then don't use the main node style on them. For the positioning, use below=of 1 instead of above=1 and it should work out.

Also, you can combine your \paths into a single one and use the scoping properties to limit the repetition.

\documentclass{standalone}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{amsmath,tikz}
\usetikzlibrary{patterns,matrix,arrows,positioning}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
  thick,main node/.style={circle,fill=RoyalBlue!90!green!80,draw,font=\sffamily\Large\bfseries}]
  \node[main node] [label=above:Cause](1) {Y};
  \node[main node] [label=above:Effect](2) [right of=1] {X};
  \node(3)[below=2cm of 1] {$N_X$};
  \node(4)[below=2cm of 2] {$N_Y$};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge [right] node[below right] {$\varphi$} (2)
    (2) edge [bend right,color=orange] node[above] {$\varphi^{-1}$} (1)
    (3) edge [color=red] node[right] {id} (1)
    (4) edge[color=blue] (2);
\end{tikzpicture}
\end{document}

sample code output

share|improve this answer
    
below=of doesn't work. Still without that I am not capable of making the background of nodes invisible but they are white! –  Naji May 3 '13 at 18:26
3  
@Naji: You need to load the positioning library to use below=of. See my code example. –  Matthew Leingang May 3 '13 at 18:27
add comment

Here a variant without positioning, without this library it's more easy to scale the graph and finally the code is more easy to read at (3,-2) is shorter than below=2cm of 1. Possible is \def\deltax{3} \def\deltay{-2}

\documentclass{standalone}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,shorten <=1pt,auto,
  scale=2,thick,
  main/.style={circle,fill=RoyalBlue!90!green!80,draw,font=\sffamily\Large\bfseries}]
  \node[main] [label=above:Cause]  (x)  at (0,0)  {X};
  \node[main] [label=above:Effect] (y)  at (3,0)  {Y};
  \node                            (nx) at (0,-2) {$N_X$};
  \node                            (ny) at (3,-2) {$N_Y$};

  \path [every node/.style={font=\sffamily\small}]
     (x)  edge [<-,right]               node[below] {$\varphi$}      (y)
          edge [bend left,color=orange] node[above] {$\varphi^{-1}$} (y)
          edge [<-,color=blue]                                       (nx)
     (ny) edge [color=red] node[right] {id} (y) ;
\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.