7

I am drawing a process flow diagram using TikZ. My code is the following:

\documentclass{minimal}

\usepackage[a4paper, landscape]{geometry}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
  [queue/.style={isosceles triangle,isosceles triangle apex angle=60,
     anchor=north,shape border rotate=90,draw,minimum width=15mm},
   activity/.style={rectangle,draw,
     anchor=north,minimum width=25mm,minimum height=15mm,
     text width=20mm,align=center}]
  \node[queue]    (tortilla queue) at (0,0) [label=below:queue 1]
      {wait};
  \node[activity] (tortilla station) [right=of tortilla queue]
      {tortilla\\station};

  \draw [->] (tortilla queue.east) -- (tortilla station.west);
\end{tikzpicture}
\end{document}

And this is the output

enter image description here

The problem with the output is that I want the base of the triangle to be aligned with the base of the rectangle. How do I do this?

I have tried to vary the anchor, or to use yshift but this doesn't work. Of course I could place the nodes manually, but this would mess up the location of the arrows.

  • Do you have a lot of repetition? because finding t he corresponding point on the triangle border is kind of tedious. – percusse Jul 28 '13 at 5:29
6

Position

You could place the rectangle relative to the lower right corner of the triangle, and specify south west as the anchor of the rectangle, that is

right=of tortilla queue.right corner,anchor=south west

Note that the anchor has to be specified after the positioning, as right=of... sets the anchor automatically.

Arrow

Note also, that to make the arrow horizontal, I've used -|, i.e.

\draw [->] (tortilla queue.east) -- (tortilla queue.east -| tortilla station.west);

which draws a line from tortilla queue.east to the point that is on the intersection of a horizontal line drawn from tortilla queue.east and a vertical line drawn from tortilla station.west.

If you like, you can get an horizontal arrow from the vertical center of the rectangle by using the intersections library to find the intersection of a horizontal line from tortilla station.west and the closest side of the triangle.

Alternative queue style

To get the text more centered in the triangle, you can use the regular polygon shape, instead of isosceles triangle. This will give the corners different names, the lower right being corner 3. So, for example

queue/.style={regular polygon,regular polygon sides=3,draw,minimum width=15mm,inner sep=1pt}

Complete code

With three different options. Screenshot below.

\documentclass[border=2mm]{standalone}

\usepackage{tikz}

\usetikzlibrary{shapes.geometric}
\usetikzlibrary{positioning,intersections}

\begin{document}
\begin{tikzpicture}
  [queue/.style={regular polygon,regular polygon sides=3,draw,minimum width=15mm,inner sep=1pt},
  old queue/.style={isosceles triangle,isosceles triangle apex angle=60,
         anchor=north,shape border rotate=90,draw,minimum width=15mm},
   activity/.style={rectangle,draw,
     anchor=north,minimum width=25mm,minimum height=15mm,
     text width=20mm,align=center}]

  % original queue style  
  \node[old queue]    (tortilla queue) at (0,0) [label=below:queue 1]
        {wait};
  \node[activity] (tortilla station) [right=of tortilla queue.right corner,anchor=south west]
        {tortilla\\station};

    \draw [->] (tortilla queue.east) -- (tortilla queue.east -| tortilla station.west);     


  % new queue style     
  \node[queue]    (tortilla queue) at (0,-3) [label=below:queue 1]
      {wait};
  \node[activity] (tortilla station) [right=of tortilla queue.corner 3,anchor=south west]
      {tortilla\\station};

  \draw [->] (tortilla queue.east) -- (tortilla queue.east -| tortilla station.west);


  % new queue style, and arrow to center of rectangle
  \node[queue]    (tortilla queue) at (0,-5.4) [label=below:queue 1]
      {wait};
  \node[activity] (tortilla station) [right=of tortilla queue.corner 3,anchor=south west]
      {tortilla\\station};

  \path [name path=from rect] (tortilla station.west) -| (tortilla queue.corner 1);
  \path [name path=triangle side] (tortilla queue.corner 1) -- (tortilla queue.corner 3);

  \draw [->,name intersections={of=from rect and triangle side}] (intersection-1) -- (tortilla station.west);

\end{tikzpicture}
\end{document}

enter image description here

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.