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.

I'm having trouble with the labels in my diagram. I want them closer to the lines, but I can't seem to find a way. Is there any way to put the labels closer to the lines?

Here is the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto, minimum width = 3em, minimum height = 3em,
  thick, main node/.style={rectangle,fill=white,draw}
 ]

  \node[main node,node distance=3cm] (2) {I(t)};
  \node[main node,node distance=3cm] (1) [left of=2] {S(t)};
  \node[main node,node distance=3cm] (3) [right of=2] {A(t)};
  \node[below of=1,node distance=2cm] (dummy1) {};
  \node[below of=2,node distance=2cm] (dummy2) {};
  \node[below of=3,node distance=2cm] (dummy3) {};
  \node[right of=3,node distance=2cm] (dummy4) {};
  \node[left of=1,node distance=2cm] (dummy) {};


 \draw[->,draw=black] (1)  -- node {$\lambda(t)$} (2);
 \draw[->,draw=black] (2)  -- node {$\alpha$} (3);
 \draw[->,draw=black] (dummy) -- node {$\Lambda$} (1);
 \draw[->,draw=black] (1) -- node {$\mu$} (dummy1);
 \draw[->,draw=black] (2) -- node {$\mu$} (dummy2);
 \draw[->,draw=black] (3) -- node {$\mu$} (dummy3);
 \draw[->,draw=black] (3) -- node {$\nu$} (dummy4);

\end{tikzpicture}
\end{document}

enter image description here

share|improve this question

2 Answers 2

up vote 6 down vote accepted

You have set a node size with a minimum of 3ems in both width and height within the whole tikzpicture environment while this should only be associated with the main node/.style. Here is what I mean:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,
  thick, main node/.style={rectangle,fill=white,draw, minimum width = 3em, minimum height = 3em}
 ]

  \node[main node,node distance=3cm] (2) {I(t)};
  \node[main node,node distance=3cm] (1) [left of=2] {S(t)};
  \node[main node,node distance=3cm] (3) [right of=2] {A(t)};
  \node[below of=1,node distance=2cm] (dummy1) {};
  \node[below of=2,node distance=2cm] (dummy2) {};
  \node[below of=3,node distance=2cm] (dummy3) {};
  \node[right of=3,node distance=2cm] (dummy4) {};
  \node[left of=1,node distance=2cm] (dummy) {};


 \draw[->,draw=black] (1)  -- node [outer ysep=0pt]{$\lambda(t)$} (2);
 \draw[->,draw=black] (2)  -- node {$\alpha$} (3);
 \draw[->,draw=black] (dummy) -- node {$\Lambda$} (1);
 \draw[->,draw=black] (1) -- node {$\mu$} (dummy1);
 \draw[->,draw=black] (2) -- node {$\mu$} (dummy2);
 \draw[->,draw=black] (3) -- node {$\mu$} (dummy3);
 \draw[->,draw=black] (3) -- node {$\nu$} (dummy4);

\end{tikzpicture}
\end{document}

With the expected output:

enter image description here

share|improve this answer
    
node distance is not global here. It is local to the paths. –  percusse Aug 11 at 21:55
    
I mean global to the tikzpicture environment not to a specific path. –  AboAmmar Aug 11 at 21:57
    
I mean there is no node distance set globally. But that's what you are saying at the first sentence. –  percusse Aug 11 at 21:58
    
I edited this to prevent any confusion. Thanks for the notion. –  AboAmmar Aug 11 at 22:03
    
It is not actually related to node distance. See my answer. node distance sets the distance between nodes. Here it is the node that is big. –  percusse Aug 11 at 22:08

If you put this line between two blocks of code

\tikzset{every node/.style={draw}}

this is what you would see

enter image description here

You can see that all of them have extra spacing around the math text inside them. This is because the tikzpicture options you have provided minimum width = 3em, minimum height = 3em applies to everything unless you override them.

One option is as AboAmmar showed, take them into the mainnode style or use

\tikzset{every node/.style={minimum size=0pt}}

to reset the options after the first chunk of code..

share|improve this answer

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.