I am new to latex and tikz and wanted to draw a block diagram using it. But I am having some issues. Can somebody help me with the few questions I have?
-
How to write 'this text'so that it's in the middle of the filled box and not have boxes for text0 and text 6?
-
How to write text between the boxes or on top of the arrow?
-
Is there a way to control the size of individual boxes and have different arrow shape?
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,fit,backgrounds}
\tikzstyle{block} = [draw, rectangle, align=center, text width=2.4cm, text centered, minimum height=1.2cm, node distance=3.5cm,fill=white]
\tikzstyle{container} = [draw, rectangle, inner sep=0.3cm, fill=gray,minimum height=3cm]
\def\bottom#1#2{\hbox{\vbox to #1{\vfill\hbox{#2}}}}
\tikzset{
mybackground/.style={execute at end picture={
\begin{scope}[on background layer]
\node[] at (current bounding box.north){\bottom{1cm} #1};
\end{scope}
}},
}
\begin{document}
\resizebox{14cm}{3cm}{%
\begin{tikzpicture}[>=latex',mybackground={This text}]
\node [block, name= text0] (text0){text0};
\node [block, right of=text0](text1) {text1};
\node [block, right of=text1] (text2) {text2};
\node [block, right of=text2] (text3) {text3};
\node [block, right of=text3] (text4) {text4};
\node [block, right of=text4] (text5) {text5};
\node [block, right of=text5] (text6) {text6};
\begin{scope}[on background layer]
\node [container,fit= (text3) (text4)] (container) {};
\end{scope}
\draw [->] (text0) -- (text1);
\draw [->] (text1) -- (text2);
\draw [->] (text2) -- node {}(text3);
\draw [->] (text3) -- node {}(text4);
\draw [->] (text4) -- node {} (text5);
\draw [->] (text5) -- node {} (text6);
\end{tikzpicture}
}
\end{document}
Best Answer
hopefully the example below fulfill all your requests:
chains
library for their positioning (assumed, that distances between are equal, however, if some of the are different, this can be changed with local useright=of <name previous block>
quotes
as(<node name i>) edge [" your text"] (<node name i+1>)
\resizebox
! it lead to bad looking of image. rather resize block, font and distances between blocksarrows.meta
you can simply adjust arrow head size (length, width, angle, etc). for details see "tikz & pgf manual, v 3.0.1a", section "16.5 Reference: Arrow Tips", page 201. in mwe below i use default values, however you can experimenting with for example (see page 209 of mentioned manual):