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 code

% compilation command: pdflatex --jobname=Diag-f1 Diag.tex
\documentclass{book}
\usepackage{tikz}
\pgfrealjobname{Diag}
\begin{document}
\beginpgfgraphicnamed{Diag-f1}
\begin{tikzpicture}[node distance=3em]
\node(G)[rectangle,fill=red!5,draw=red,text width=5cm]{};
\node(H)[below of=G]{H};
\node(H1)[left of=H]{H1};
\node(H2)[right of=H]{H2};
\draw[->](G.south)-|(H1.north);
\draw[->](G.south)--(H.north);
\draw[->](G.south)-|(H2.north);
\end{tikzpicture}
\endpgfgraphicnamed
\end{document}

enter image description here

but I am not happy with the two arrows going from G.south to H1.north and H2.north. Because of the -| command, there is a spurious horizontal line. How can I achieve the same result without this annoying horizontal line? \draw[->](G.south)--(H1.north); is not a solution. There are available tricks but I may have missed an obvious solution here.

share|improve this question
add comment

2 Answers 2

up vote 20 down vote accepted

The line is normal: -| means: draw an horizontal line, then a vertical.

You could use this:

\draw[->] (G.south -| H1.north) -- (H1.north)

That will compute the intersection between a vertical line through H1.north and a horizontal one through G.south, and then draw a line from it to H1.north

share|improve this answer
add comment

I like the use of to paths.

Advantage: The target coordinate/node has only to be given once.

Code

\documentclass[tikz]{standalone}
\tikzset{
    -|/.style={
        to path={
            (perpendicular cs: horizontal line through={(\tikztostart)},
                                 vertical line through={(\tikztotarget)})
            % is the same as (\tikztostart -| \tikztotarget)
            % but just to be safe: http://tex.stackexchange.com/a/29781/16595
            -- (\tikztotarget) \tikztonodes
        }
    }
}
\begin{document}
\begin{tikzpicture}[node distance=3em]
\node(G)  [rectangle,fill=red!5,draw=red,text width=5cm] {};
\node(H)  [below of=G] {H};
\node(H1) [left of=H]  {H1};
\node(H2) [right of=H] {H2};
\draw[->,-|] (G.south) to     (H1.north);
\draw[->]    (G.south) --     (H.north);
\draw[->]    (G.south) to[-|] (H2.north);
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer
    
very nice solution as well. Thanks –  pluton Dec 18 '12 at 15:38
add comment

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.