4

I want to refine the following diagram. I want to left allign the text showing on the left of this diagram and need straight paths. Any help will be highly appreciated. Thanks

enter image description here

\documentclass[tikz]{standalone} \usepackage{pgf} \usepackage{tikz} \usetikzlibrary{arrows, automata, calc} \usepackage[latin1]{inputenc} \begin{document} \begin{tikzpicture}[ -> , >=stealth' , shorten >=1pt , auto , node distance=1.0cm , semithick ] \tikzstyle{every state}=[ fill=white , draw=none , align=left %, text width=9cm , text=black ] \node[state] (TotalNi) {Total Ni}; \node[state] (AN) [below of=TotalNi] {AN}; \node[state] (CC) [below of=AN] {CC}; \node[state] (SC) [below of=CC] {SC}; \node[state] (EDTA) [below of=SC] {EDTA}; \node[state] (ABDTPA) [below of=EDTA] {ABDTPA}; \node[state] (DTPA) [below of=ABDTPA] {DTPA}; \node at (5,-6.0) [draw,name=u1,rectangle, minimum width=2cm,minimum height=5.75cm,anchor=south,transform shape] {Test}; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (TotalNi) edge node {\textcolor{red}{$-0.06557$}} (u1.north west) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (AN) edge node {\textcolor{blue}{$0.04305$}} (u1) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (CC) edge node {\textcolor{red}{$-0.34954$}} (u1) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (SC) edge node {\textcolor{red}{$-0.34954$}} (u1) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (EDTA) edge node {\textcolor{red}{$-0.34954$}} (u1) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (ABDTPA) edge node {\textcolor{red}{$-0.34954$}} (u1) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (DTPA) edge node {\textcolor{red}{$-0.34954$}} (u1.south west) ; \end{tikzpicture} \end{document} 

2 Answers 2

3
\documentclass[tikz,margin=5]{standalone} \usepackage{pgf} \usepackage{tikz} \usetikzlibrary{arrows, automata, calc,fit} \usepackage[latin1]{inputenc} \begin{document} \begin{tikzpicture}[ -> , >=stealth' , shorten >=1pt , auto , node distance=1.0cm , semithick ] \tikzset{every state/.style ={ % fill=white , draw=none , anchor = west , rectangle , minimum width= 1.5cm , text width = 1.4cm , text=black } } \node[state] (TotalNi) {Total Ni}; \node[state] (AN) [below of=TotalNi] {AN}; \node[state] (CC) [below of=AN] {CC}; \node[state] (SC) [below of=CC] {SC}; \node[state] (EDTA) [below of=SC] {EDTA}; \node[state] (ABDTPA) [below of=EDTA] {ABDTPA}; \node[state] (DTPA) [below of=ABDTPA] {DTPA}; \node[draw,rectangle,xshift=5cm] [fit = (TotalNi) (AN)(CC) (SC) (EDTA) (ABDTPA) (ABDTPA) (DTPA)] (u1) {Test}; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (TotalNi.east) edge node {\textcolor{red}{$-0.06557$}} ($(u1.north west)!(TotalNi.east)!(u1.south west)$) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (AN) edge node {\textcolor{blue}{$0.04305$}} ($(u1.north west)!(AN.east)!(u1.south west)$) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (CC) edge node {\textcolor{red}{$-0.34954$}} ($(u1.north west)!(CC)!(u1.south west)$) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (SC) edge node {\textcolor{red}{$-0.34954$}} ($(u1.north west)!(SC)!(u1.south west)$) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (EDTA) edge node {\textcolor{red}{$-0.34954$}} ($(u1.north west)!(EDTA)!(u1.south west)$) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (ABDTPA) edge node {\textcolor{red}{$-0.34954$}} ($(u1.north west)!(ABDTPA.east)!(u1.south west)$) ; \path[sloped, above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (DTPA) edge node {\textcolor{red}{$-0.34954$}} ($(u1.north west)!(DTPA.east)!(u1.south west)$) ; \end{tikzpicture} \end{document} 

enter image description here

Here is another version.

\documentclass[tikz,margin=5]{standalone} \usepackage{tikz} \usetikzlibrary{arrows,calc,fit} \tikzset{ -> , >=stealth' , shorten >=1pt, my node/.style = {align=left,anchor=west}, your node/.style={above,pos=1,xshift=-2cm,text = red} } \begin{document} \begin{tikzpicture} \node[my node] (TotalNi) at (0,0) {Total Ni}; \node[my node] (AN) at (0,-1) {AN}; \node[my node] (CC) at (0,-2) {CC}; \node[my node] (SC) at (0,-3) {SC}; \node[my node] (EDTA) at (0,-4) {EDTA}; \node[my node] (ABDTPA) at (0,-5) {ABDTPA}; \node[my node] (DTPA) at (0,-6) {DTPA}; \node[draw,rectangle,xshift=5cm] [fit = (TotalNi) (AN)(CC) (SC) (EDTA) (ABDTPA) (ABDTPA) (DTPA)] (u1) {\rotatebox{90}{Test}}; \draw[->](TotalNi.east) -- node[your node] {$-0.06557$} ($(u1.north west)!(TotalNi.east)!(u1.south west)$) ; \draw[->] (AN) -- node[your node,text = blue] {$\phantom{-}0.04305$} ($(u1.north west)!(AN.east)!(u1.south west)$) ; \draw[->] (CC) -- node[your node] {$-0.34954$} ($(u1.north west)!(CC)!(u1.south west)$) ; \draw[->] (SC) -- node[your node] {$-0.34954$} ($(u1.north west)!(SC)!(u1.south west)$) ; \draw[->] (EDTA) -- node[your node] {$-0.34954$} ($(u1.north west)!(EDTA)!(u1.south west)$) ; \draw[->] (ABDTPA) -- node[your node] {$-0.34954$} ($(u1.north west)!(ABDTPA.east)!(u1.south west)$) ; \draw[->] (DTPA) -- node[your node] {$-0.34954$} ($(u1.north west)!(DTPA.east)!(u1.south west)$) ; \end{tikzpicture} \end{document} 

enter image description here

2
  • Thanks @HarishKumar for your nice answer. Would you guide me how to rotate the text (here Test) in the right most triangle. Thanks Commented Nov 3, 2014 at 8:17
  • @MYaseen208 Use \rotatebox as an ugly short cut. Commented Nov 3, 2014 at 8:42
4

I think that the code of the figure can be reduced (and imho improved) by using a foreach loop for the final part. In addition the syntax (a-|b) can be useful to specify the coordinate at which each line ends, being a the node containing the label and b the "west" side of the large box.

Also, since I noticed that the color of the numbers is based on their signs, this can be automated too.

Using these ideas, the code can be simplified to:

 % All the code up to the line % \node[draw,rectangle,xshift=5cm] [fit = (TotalNi) (AN)(CC) (SC) (EDTA) (ABDTPA) (ABDTPA) (DTPA)] (u1) {Test}; % remains identical % This loop draws all the lines and numbers \foreach \label/\amount in { TotalNi/-0.06557, AN/0.04305, CC/-0.34954, SC/-0.34954, EDTA/-0.34954, ABDTPA/-0.34954, DTPA/-0.34954} { \pgfmathparse{ifthenelse(\amount<0,"red","blue")} \path[above, pos=0.4, yshift=0.1cm, anchor=south, auto=false] (\label) edge node {\textcolor{\pgfmathresult}{$\amount$}} (\label-|u1.west); } 

Result:

Result

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.