6

I have the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,arrows,shapes,snakes,automata,backgrounds,petri,positioning}
\tikzset{
myshape/.style={
  rectangle split,
  minimum height=1.5cm,
  rectangle split horizontal,
  rectangle split parts=2, 
  draw,
  text width=2cm,
  anchor=center,
  }
}
\begin{document}
\begin{tikzpicture}[scale = 0.2,bend angle = 35, inner sep=2mm,
queue/.style={rectangle split, rectangle split horizontal,rectangle split draw splits = false,rectangle split part fill = {white!100,####1} , rectangle split parts=2, draw, anchor=center, minimum height = 1cm},
dispatcher/.style={rectangle,draw=blue!50!black,fill=blue!20!white,thick, minimum height = 1cm, minimum width = 1.5cm}]
\node[dispatcher] (disp) {};
\node[queue = gray!50] (queue2) [above right= 0.1cm and 3cm of disp] {$\qquad$  \nodepart{two}$\qquad \qquad \qquad \qquad$};
\node[queue = red!50] (queue1) [above=0.3cm of queue2] {$\qquad\qquad \qquad$  \nodepart{two}$\qquad \qquad$}
edge [pre, bend right,line width = 0.4mm] (disp.east)
;
\node[queue = green!50] (queue3) [below right=0.1cm and 3cm of disp] {$\qquad\qquad \qquad \qquad$  \nodepart{two}$\qquad$} 
edge [pre, bend left,line width = 0.4mm] (disp.east);
\node[queue = red!50] (queue4) [below=0.3cm of queue3] {$\qquad$  \nodepart{two}$\qquad \qquad \qquad \qquad$} 
edge [pre, bend left, line width = 0.4mm] (disp.east);
\draw[loosely dotted, line width = 0.4mm] (queue2) -- (queue3);
\end{tikzpicture}
\end{document}

which produces the following picture:

picture

I was wondering what I should change to do the following:

  • Put some text on top of the arrows.
  • Let the arrows end at the west side of the queues.
5

You should specify explicitly the begin and end of the arrows. An easy way to connect these arrows is using edge and text is added by using node[above,pos=.9]{text}.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,arrows,shapes,snakes,automata,backgrounds,petri,positioning}
\tikzset{
    myshape/.style={
        rectangle split,
        minimum height=1.5cm,
        rectangle split horizontal,
        rectangle split parts=2, 
        draw,
        text width=2cm,
        anchor=center,
    }
}
\begin{document}
    \begin{tikzpicture}[scale = 0.2,bend angle = 35, inner sep=2mm,
    queue/.style={rectangle split, rectangle split horizontal,rectangle split draw splits = false,rectangle split part fill = {white!100,#1} , rectangle split parts=2, draw, anchor=center, minimum height = 1cm},
    dispatcher/.style={rectangle,draw=blue!50!black,fill=blue!20!white,thick, minimum height = 1cm, minimum width = 1.5cm}]
    \node[dispatcher] (disp) {};
    \node[queue = gray!50] (queue2) [above right= 0.1cm and 3cm of disp] {$\qquad$  \nodepart{two}$\qquad \qquad \qquad \qquad$};
    \node[queue = red!50] (queue1) [above=0.3cm of queue2] {$\qquad\qquad\qquad$  \nodepart{two}$\qquad \qquad$};
    \node[queue = green!50] (queue3) [below right=0.1cm and 3cm of disp] {$\qquad\qquad\qquad\qquad$\nodepart{two}$\qquad$};
    \node[queue = red!50] (queue4) [below=0.3cm of queue3] {$\qquad$\nodepart{two}$\qquad\qquad\qquad\qquad$};
    \draw[loosely dotted, line width = 0.4mm] (queue2) -- (queue3);
    \path (disp.east) edge [->, bend right,line width = 0.4mm]node[above,pos=.85]{text3} (queue3.west)
                      edge [->, bend right,line width = 0.4mm]node[above,pos=.9]{text4} (queue4.west)
                      edge [->, bend left,line width = 0.4mm]node[above,pos=.9]{text1} (queue1.west);
    \end{tikzpicture}
\end{document}

enter image description here

  • Thank you for your answer, you also made the code much more readable! – HolyMonk Jan 5 '18 at 22:27
7

I could not get your code compiling until I replaced ####1 by #1 in line 19. If you have more complicated annotations, you may find it more convenient to replace the loop by explicit commands.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,arrows,shapes,snakes,automata,backgrounds,petri,positioning}
\tikzset{
myshape/.style={
  rectangle split,
  minimum height=1.5cm,
  rectangle split horizontal,
  rectangle split parts=2, 
  draw,
  text width=2cm,
  anchor=center,
  }
}
\begin{document}
\begin{tikzpicture}[scale = 0.2,bend angle = 35, inner sep=2mm,
queue/.style={rectangle split, rectangle split horizontal,rectangle split draw splits = false,rectangle split part fill = {white!100,#1} , rectangle split parts=2, draw, anchor=center, minimum height = 1cm},
dispatcher/.style={rectangle,draw=blue!50!black,fill=blue!20!white,thick, minimum height = 1cm, minimum width = 1.5cm}]
\node[dispatcher] (disp) {};
\node[queue = gray!50] (queue2) [above right= 0.1cm and 3cm of disp] {$\qquad$  \nodepart{two}$\qquad \qquad \qquad \qquad$};
\node[queue = red!50] (queue1) [above=0.3cm of queue2] {$\qquad\qquad \qquad$  \nodepart{two}$\qquad \qquad$}(disp.east);
\node[queue = green!50] (queue3) [below right=0.1cm and 3cm of disp] {$\qquad\qquad \qquad \qquad$  \nodepart{two}$\qquad$} (disp.east);
\node[queue = red!50] (queue4) [below=0.3cm of queue3] {$\qquad$  \nodepart{two}$\qquad \qquad \qquad \qquad$} (disp.east);
\draw[loosely dotted, line width = 0.4mm] (queue2) -- (queue3);
\foreach \a in {1,...,4}
{\draw[ultra thick, in=180,out=50-\a*20,thick,->] (disp.east) to
node[midway,above] {\a}
(queue\a.west);
};
\end{tikzpicture}
\end{document}

enter image description here

  • Thank you for your answer, I also really like the curvature you gave the arrows! I use the ####1 because I am actually working on a beamer presentation and if I use #1 it gives me some error. – HolyMonk Jan 5 '18 at 22:28
  • 1
    @HolyMonk I'd propose to make your MWE compilable by either using #1 or by using the beamer class. – marmot Jan 5 '18 at 22:30
5

slightly modification of nice marmot answer. adopted to beamer document class, with simplified arrows, use of chains and quotes library. All not used tikz libraries and style definition are removed to obtain mwe (minimal working example):

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, chains, quotes, positioning, shapes.multipart}

\tikzset{scheduler/.style = {
node distance = 3mm and 33mm,
  start chain = A going below,
 queue/.style = {rectangle split, rectangle split horizontal, rectangle split parts=2,
                rectangle split draw splits=false,
                rectangle split part fill={white!100,##1},
                draw, minimum height = 1cm,
                on chain=A},
dispatcher/.style = {rectangle, draw=blue!50!black, fill=blue!20!white, thick,
                minimum height=1cm, minimum width = 1.5cm},
every edge quotes/.append style = {auto, anchor=south east, sloped, pos=0.9}
                    }}

\begin{document}
\begin{frame}
\frametitle{Scheduler}
    \begin{tikzpicture}[scheduler]
\node[queue=gray]   {$\qquad$
                     \nodepart{two}$\qquad \qquad \qquad \qquad$};
\node[queue=red]    {$\qquad\qquad \qquad$
                     \nodepart{two}$\qquad \qquad$};
\node[queue=green,below=16mm of A-2]
                    {$\qquad\qquad \qquad \qquad$
                     \nodepart{two}$\qquad$};
\node[queue=red!50] {$\qquad$
                     \nodepart{two}$\qquad \qquad \qquad \qquad$};
%
\node[dispatcher,below left=of A-2] (disp)  {};
%
\draw[loosely dotted, line width=0.4mm,
      shorten >=1mm, shorten <=1mm] (A-2) -- (A-3);
\path[thick,-Stealth]
        (disp.east) edge ["text 1"]  (A-1.west)
        (disp.east) edge ["text 2"]  (A-2.west)
        (disp.east) edge ["text 3"]  (A-3.west)
        (disp.east) edge ["text 4"]  (A-4.west);
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

4

I guess it would be the easiest way to first define your nodes:

\documentclass{article}
...  
\node[dispatcher] (disp) {};
\node[queue = gray!50] (queue2) [above right= 0.1cm and 3cm of disp] {$\qquad$ \nodepart{two}$\qquad \qquad \qquad \qquad$};
\node[queue = red!50] (queue1) [above=0.3cm of queue2] {$\qquad\qquad \qquad$ \nodepart{two}$\qquad \qquad$};
\node[queue = green!50] (queue3) [below right=0.1cm and 3cm of disp] {$\qquad\qquad \qquad \qquad$ \nodepart{two}$\qquad$};  
\node[queue = red!50] (queue4) [below=0.3cm of queue3] {$\qquad$ \nodepart{two}$\qquad \qquad \qquad \qquad$};

And second draw arrows and label them:

\draw[<-, bend right, line width = 0.4mm] (queue1) -- (disp) node [auto] {your text};  
\draw[<-, bend left, line width = 0.4mm] (queue3) -- (disp) node [auto] {your text};  
\draw[<-, bend left, line width = 0.4mm] (queue4) -- (disp) node [auto] {your text};  
\draw[loosely dotted, line width = 0.4mm] (queue2) -- (queue3);
\end{tikzpicture}
\end{document}

This post might be of help regarding your questions.

I don't know if you know the TikZ & PGF Manual? This manual might be a bit overwhelming at first, but I think it is very useful. Take a look at chapters 3.10 and 3.12 they should be of help regarding your questions too. :-)

  • I read the introductory tutorial, so I did read this part, but I guess not good enough! Thank you. – HolyMonk Jan 6 '18 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.