Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following tikZ graph:

enter image description here

produced by:

\tikzset{actor/.style={
        rectangle,
        minimum size=6mm,
        very thick,
        draw=red!50!black!50,
        top color=white,
        bottom color=red!50!black!20
    }}
    \tikzset{arrow/.style={
        -latex, thick
    }}
        \begin{tikzpicture}[
             background rectangle/.style={fill=yellow!10,rounded corners=1ex},        show background rectangle,
            node distance=5mm and  8mm
        ]
            \node (Input) [align=center]{GZip\\Stream};
            \node (HeaderParser) [actor, right=of Input] {HeaderParser};
            \node (HeaderCrc) [actor,above =of HeaderParser] {Crc Header};
                    \node (Inflate) [actor, right=of HeaderParser] {Inflate};
            \node (Crc) [actor,above =of Inflate] {Crc};
            \node (FooterParser) [actor,right=of Inflate] {Footer Parser};
            \node (Output) [right=of FooterParser,align=center]{Decoded\\Stream};
            \draw[arrow] (Input.east)--(HeaderParser.west);
            \draw[arrow] (HeaderParser.north)--(HeaderCrc.south);
            \draw[arrow] (HeaderParser.east)--(Inflate.west);
            \draw[arrow] (Inflate.north)--(Crc.south);
            \draw[arrow] (Inflate.east)--(FooterParser.west);
            \draw[arrow] (FooterParser.east)--(Output.west);
            \draw[arrow] (Crc.east)--(FooterParser.west);
        \end{tikzpicture}

I am almost happy with it excepted about the arrows. I don't like the arrows end and the 2 arrows ending on the same node. How can I improve this ?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

The shorten keys allows for more space around the nodes (without using outer sep and other hacks). This can really clean up a figure.

Secondly make the downward arrow go in straight lines using -| (|- for the other way).

And lastly, you do not need the east|north|south|west unless you are using curved lines, an -- will be interpreted as the shortest path between the two objects (which in this case are east -- west and south -- north).

So basically I would do:

\tikzset{actor/.style={
        rectangle,
        minimum size=6mm,
        very thick,
        draw=red!50!black!50,
        top color=white,
        bottom color=red!50!black!20
    },
    arrow/.style={
        -latex, thick, shorten <=2pt,shorten >=2pt
    }
}
\begin{tikzpicture}[background rectangle/.style={
      fill=yellow!10,rounded corners=1ex
  }, 
  node distance=5mm and 8mm]
  \node (Input) [align=center]{GZip\\Stream};
  \node (HeaderParser) [actor, right=of Input] {HeaderParser};
  \node (HeaderCrc) [actor,above =of HeaderParser] {Crc Header};
  \node (Inflate) [actor, right=of HeaderParser] {Inflate};
  \node (Crc) [actor,above =of Inflate] {Crc};
  \node (FooterParser) [actor,right=of Inflate] {Footer Parser};
  \node (Output) [right=of FooterParser,align=center]{Decoded\\Stream};
  \draw[arrow] (Input)--(HeaderParser);
  \draw[arrow] (HeaderParser)--(HeaderCrc);
  \draw[arrow] (HeaderParser)--(Inflate);
  \draw[arrow] (Inflate)--(Crc);
  \draw[arrow] (Inflate)--(FooterParser);
  \draw[arrow] (FooterParser)--(Output);
  \draw[arrow] (Crc)-|(FooterParser);
\end{tikzpicture}

Which gives:

enter image description here

A last way out is to join the two lines before FooterParser, for this you need the calc library:

\draw[thick,shorten <=2pt] (Crc)-|($(Inflate.east)!.5!(FooterParser.west)$);

This will yield:

Maybe this is not so pretty, however, it can be used

share|improve this answer
    
Thanks for the clear and complete answer. just one more thing, the "rounded" effect of arrows end causes "rendering issue" depending on zoom level of the PDF viewer. The screen shot I took is viewing the PDF with zoom = 100%. How can I change that ? –  Manuel Selva Sep 12 '12 at 8:02
    
Rendering of zoom has nothing to do with the TikZ code, search around for this issue. It has been brought up several times and is an issue with the rendering machine in the viewer. :) –  zeroth Sep 12 '12 at 8:09
    
Yes I understand that ;-) so what viewer did you use to take your screenshot, they are nice ? –  Manuel Selva Sep 12 '12 at 8:12
1  
I didn't take a screenshot :) I used imagemagick. convert -trim -density <resolution> <filename>.pdf <filename>.png. –  zeroth Sep 12 '12 at 8:16
    
This looks very nice and professional, +1. –  Alexander Sep 12 '12 at 13:51

If you don't like the end arrow you can change it: there's an entire section dedicated to this on the pgfmanual (see 23 Arrow Tip Library, version October 25, 2010).

For what concern the ending connection point for the FooterParser node, one could even specify the boundary angle in which the arrow ends. To better understand this, see the following answer: Alignments by means of the tikzmark macro.

See the following MWE (BTW: the one posted is not a minimal working example) in which as arrow tip I used stealth and as end connection point FooterParser.175:

 \documentclass{article}

 \usepackage{tikz}
 \usetikzlibrary{arrows,backgrounds,positioning}

\tikzset{actor/.style={
        rectangle,
        minimum size=6mm,
        very thick,
        draw=red!50!black!50,
        top color=white,
        bottom color=red!50!black!20
    }}
    \tikzset{arrow/.style={
        -stealth, thick
    }}


\begin{document}

\begin{tikzpicture}[
             background rectangle/.style={fill=yellow!10,rounded corners=1ex},        show background rectangle,
            node distance=5mm and  8mm
        ]
            \node (Input) [align=center]{GZip\\Stream};
            \node (HeaderParser) [actor, right=of Input] {HeaderParser};
            \node (HeaderCrc) [actor,above =of HeaderParser] {Crc Header};
                    \node (Inflate) [actor, right=of HeaderParser] {Inflate};
            \node (Crc) [actor,above =of Inflate] {Crc};
            \node (FooterParser) [actor,right=of Inflate] {Footer Parser};
            \node (Output) [right=of FooterParser,align=center]{Decoded\\Stream};
            \draw[arrow] (Input.east)--(HeaderParser.west);
            \draw[arrow] (HeaderParser.north)--(HeaderCrc.south);
            \draw[arrow] (HeaderParser.east)--(Inflate.west);
            \draw[arrow] (Inflate.north)--(Crc.south);
            \draw[arrow] (Inflate.east)--(FooterParser.west);
            \draw[arrow] (FooterParser.east)--(Output.west);
            \draw[arrow] (Crc.east)--(FooterParser.175);
        \end{tikzpicture}

\end{document}

Result:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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