Please help me to draw this diagram in LaTeX
2 Answers
An alternative to your solution:
Main differences in comparison to your solution:
- as document class is used
standalone
with optiontikz
. With it you can see only images. When you are satisfied with result, you can copy code to final document or include it with\input{<path>/<picture file name>}
- style difinition is part of
tikzpicture
options (use oftikzstyle
is now depreciated, instead it is preferable\tikzset{...}
, where styles had to be defined on the same way as intikzpicture
options) - for node style I rather use mynode instead of yours node. Use node for style name is not good since it is already defined in TikZ for node ...
- for shape of main nodes i select
signal
. Using it I avoid all your scaling of regular polygon and have better control on shape size - in positioning of nodes I rather use relative coordinates to coordinate of the main nodes. in this I exploit
positioning
library. Their distances are controlled bynode distance = <vertical> and <horizontal>
- for drawing arrows I define auxiliary coordinates
- arrows are grouped by
scope
regarding their common features (dash pattern, direction) - not at the end, I write code in my editor and for shape data look into TikZ & PGF manual, chapter 67 Shape Library, page 693 (shapes
signal
are described in section 67.4 Symbol Shapes, see page 713).
Complete MWE:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning, shapes.symbols}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 16mm,
mynode/.style = {shape=signal, signal to=west and east,
draw, color = #1,
text width=1.3cm, align=flush center,
inner xsep=0mm, inner ysep=2mm, font=\small}
]
% main nodes
\node (A) [mynode=magenta] {Text 2};
\node (B) [mynode=blue, below=of A] {Text 3};
\node (C) [mynode=teal, below=of B] {Text 4};
% coordinates for lines
\coordinate[left=of B.west] (in2);
\coordinate[left=of in2] (in1);
\coordinate[right=of B.east] (out1);
\coordinate[right=of out1] (out2);
% dashed arrows
\begin{scope}[latex-, dashed, shorten >=1mm]
\draw[magenta] (A.west) -- + (-0.8,0) -- (in2);
\draw[blue] (B.west) -- (in2);
\draw[magenta] (C.west) -- + (-0.8,0) -- (in2);
\end{scope}
\begin{scope}[-latex, dashed, shorten >=1mm]
\draw[magenta] (A.east) -- + (0.8,0) -- (out1);
\draw[blue] (B.east) -- (out1);
\draw[magenta] (C.east) -- + (0.8,0) -- (out1);
\end{scope}
% arrows with text
\draw[-latex] (in1) -- node[above] {Text 1} (in2);
\draw[-latex] (out1) -- node[above] {Text 5} (out2);
%--------------
\end{tikzpicture}
\end{document}
-
Thank you very much @Zargo! Your answer and tips will help me learn more about tikz. Soon, I will be able to write this and others codes by hand. :)– LaraCommented Dec 16, 2016 at 2:11
I drew with help of tikzEdit editor (http://www.tikzedt.org/). This is the code that produces the figure
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.geometric,shapes.misc}
\begin{document}
\begin{tikzpicture}
%--------------
\tikzstyle{node} = [ regular polygon, regular polygon sides=6,xscale=2,draw,
scale=0.5,text centered,text width=1.3cm,inner sep=0pt]
%--------------
\node (v1) at (-4.5,3.5) {};
\node (v2) at (-3,3.5) {};
\draw [-latex] (v1) -- node[above] {\small Text 1} (v2);
%--------------
\draw [magenta,dashed] (v2) -- (-2.5,5) node (v3) {};
\draw [-latex,magenta,dashed] (v3) -- (-1.5,5);
\node [node,magenta] (A) at (-0.5,5) {\small Text 2};
%--------------
\draw [-latex,blue,dashed] (v2) -- (-1.5,3.5);
\node [node,blue] (B) at (-0.5,3.5) {\small Text 3};
%--------------
\draw [teal,dashed] (v2) -- (-2.5,2) node (v5) {};
\draw [-latex,teal,dashed] (v5) -- (-1.5,2);
\node [node,teal] (C) at (-0.5,2) {\small Text 4};
%--------------
\node (v6) at (2,3.5) {};
\node (v7) at (3.5,3.5) {};
%--------------
\draw [magenta,dashed] (0.6,5) -- (1.5,5) node (v8) {};
\draw [-latex,magenta,dashed] (v8) -- (v6);
\draw [-latex,blue,dashed](0.6,3.5) -- (v6);
\draw [teal,dashed] (0.6,2) -- (1.5,2) node (v9) {};
\draw [-latex,teal,dashed](v9) -- (v6);
%--------------
\draw [-latex] (v6) -- node[above] {\small Text 5} (v7);
%--------------
\end{tikzpicture}
\end{document}
-
2
-
First of all, THANK YOU VERY MUCH @Sebastiano for introducing me to tikzEdt. You were the only person who understood my question. Tikzedt is a great tool for beginners and for those who learn by themselves.– LaraCommented Dec 16, 2016 at 2:00
-
\node
makes a rectangle by default. Don't worry about what the result looks like. Concentrate on getting the structure right. Then you can post what you've got if you need help with the style.