5

I am using TikZ for making path diagram. Code is given below

\documentclass[landscape]{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=6em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]
\begin{tikzpicture}[node distance = 3cm, auto][bend angle=45]
\node [block] (sq1) {PM};
\node [block, below of=sq1] (sq2) {KP};
\node [block, below of=sq2] (sq3) {TKW};
\node [block, left of=sq1,node distance=7cm] (sq4) {PM.GMXTD};
\node [block, left of=sq2,node distance=7cm] (sq5) {KP.GHM};
\node [block, left of=sq3,node distance=7cm] (sq6) {PM.GPRF};
\node [block, below of=sq6] (sq7) {KP.GMNTD};
\node [block, right of=sq2,node distance=7cm] (sq8) {Yield};
\path [line] (sq4) -- node {0.35}(sq1);
\path [line] (sq5) -- node {0.232}(sq2);
\path [line] (sq6) -- node {0.393}(sq3);
\path [line] (sq7) -- node {0.26}(sq3);
\path [line] (sq1) -- node {0.807}(sq8);
\path [line] (sq2) -- node {1.189}(sq8);
\path [line] (sq3) -- node {0.653}(sq8);
\path [line] (sq2) -- node {-0.926}(sq3);
\path [line] (sq1) -- node {-0.65}(sq2);
\path [line] (sq1) to [bend left=45] node {-0.528}(sq3);
\path [line] (sq4) to [bend left=45] node {0.158}(sq8);
\path [line] (sq7) to [bend right=45] node {0.207}(sq8);
\path [line] (sq5) to [bend left=55] node {0.456}(sq8);
\end{tikzpicture}
\end{document}

enter image description here

I have following three questions.

1) Is it possible to change the text position along the arrows?

2) Is it possible to rotate the text along the arrow?

3) Is it possible that i can draw a box on the left middle of two boxes?

Thanks in advance.

2
  • 1
    Your first two questions can be answered with ` node[pos=0.8,sloped] {0.207}(sq8);`. I couldn't understand what you mean in your third question.
    – percusse
    Commented Feb 19, 2012 at 19:55
  • For example i need PM Box in the right middle of PM.GMXTD and KP.GHM. And similarly the KP and TKW.
    – Iftikhar
    Commented Feb 19, 2012 at 20:30

2 Answers 2

5

Here is a whirlwind of ideas for (hopefully) making things easier, although needed a lot of small manual tweaking:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\tikzset{
  mymx/.style={
    matrix of nodes, % this option is available after loading the matrix library
    nodes=block,
    row sep=2cm, % the amount of space separating the nodes vertically
    column sep=3cm, % ^same, but horizontally
  },
  block/.style={
    rectangle,
    draw,
    fill=blue!20,
    rounded corners,
    text width=6em,
    align=center,
    minimum height=4em
  },
  lbl/.style={
    above,
    sloped, % make the text follow the path
    execute at begin node={$}, % begin math mode, for the minus signs etc.
    execute at end node={$}, % end math mode
  }
}
\begin{document}
\begin{tikzpicture}
  \matrix[mymx] (mx) { % give the name "mx" to this matrix
    PM.GMXTD & PM \\
    KP.GHM   & KP & Yield \\
    PM.GPRF  & TKW \\
    KP.GMNTD \\
  };
  % now the cells of the matrix are available as, eg.:
  % (mx-1-2) means the second column on the first row
  %
  \path[-latex,every node/.style=lbl]
    (mx-1-1) edge[bend left=45] node {0.158} (mx-2-3)
             edge node {0.35} (mx-1-2)
    (mx-2-1) edge[bend left,pos=.4] node {0.456} ([yshift=-1ex]mx-2-3.north west)
             edge node {0.232} (mx-2-2)
    (mx-3-1) edge node {0.393} (mx-3-2)
    (mx-4-1) edge node {0.26} (mx-3-2)
             edge[bend right] node {0.207} (mx-2-3)
    (mx-1-2) edge node[pos=.7] {-0.65} (mx-2-2)
             edge[bend left,looseness=1.4,pos=.3] node {-0.528} (mx-3-2)
             edge node {0.807} (mx-2-3)
    (mx-2-2) edge node {1.189} (mx-2-3)
             edge node {-0.926} (mx-3-2)
    (mx-3-2) edge node {0.653} (mx-2-3)
    ;
  % to put a node in the middle of something, using the calc library:
  \begin{scope}[every node/.style={execute at begin node=\strut}]
    \node              at ($(mx-1-1)!.5!(mx-2-1)$) {mid};
    \node[anchor=west] at ($(mx-1-1.west)!.5!(mx-2-1.west)$) {left};
    \node[anchor=east] at ($(mx-1-1.east)!.5!(mx-2-1.east)$) {right};
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

2
  • Thanks for your work. It would be nice if you can answer third question as well. I can explain it as "For example i need PM Box in the right middle of PM.GMXTD and KP.GHM. And similarly the KP and TKW".
    – Iftikhar
    Commented Feb 19, 2012 at 21:03
  • @user4299: do you mean like \node at ($(mx-1-1.east)!.5!(mx-2-1.east)$) {a node};?
    – morbusg
    Commented Feb 20, 2012 at 7:44
4

for text position use [pos=0.xxx]

\begin{tikzpicture}[node distance = 3cm, auto][bend angle=45]
\node [block] (sq1) {PM};
\node [block, below of=sq1] (sq2) {KP};
\node [block, below of=sq2] (sq3) {TKW};
\node [block, left of=sq1,node distance=7cm] (sq4) {PM.GMXTD};
\node [block, left of=sq2,node distance=7cm] (sq5) {KP.GHM};
\node [block, left of=sq3,node distance=7cm] (sq6) {PM.GPRF};
\node [block, below of=sq6] (sq7) {KP.GMNTD};
\node [block, right of=sq2,node distance=7cm] (sq8) {Yield};
\path [line] (sq4) -- node[pos=0.3] {0.35}(sq1);
\path [line] (sq5) -- node[pos=0.1] {0.232}(sq2);
\path [line] (sq6) -- node[pos=0.8] {0.393}(sq3);
\path [line] (sq7) -- node {0.26}(sq3);
\path [line] (sq1) -- node {0.807}(sq8);
\path [line] (sq2) -- node {1.189}(sq8);
\path [line] (sq3) -- node {0.653}(sq8);
\path [line] (sq2) -- node {-0.926}(sq3);
\path [line] (sq1) -- node {-0.65}(sq2);
\path [line] (sq1) to [bend left=45] node[pos=0.4] {-0.528}(sq3);
\path [line] (sq4) to [bend left=45] node {0.158}(sq8);
\path [line] (sq7) to [bend right=45] node {0.207}(sq8);
\path [line] (sq5) to [bend left=55] node[pos=0.4] {0.456}(sq8);
\end{tikzpicture}

for rotate, use sloped

\path [line] (sq1) -- node[sloped] {0.807}(sq8);
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .