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.

1 Answer 1

up vote 7 down vote accepted

Here's one possibility using the intersections library from TikZ:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\node[inner xsep=0pt,inner ysep=10pt,outer sep=0pt] (#1) {};}

\begin{document}

\[
\tikzmark{c}2:\tikzmark{a}3 + 5:\tikzmark{d}3+\tikzmark{b}2:3+5:3
\]

\begin{tikzpicture}[remember picture,overlay]
\draw[name path=line1,red,->] ([xshift=2pt]a.north east) -- +(0pt,10pt) -| ([xshift=2pt]b.north east);
\path[name path=line2] ([xshift=2pt]c.north east) -- +(0pt,23pt) -| ([xshift=2pt]d.north east);
\draw[name intersections={of=line1 and line2,by={int}},draw,->,red] 
  ([xshift=2pt]c.north east) -- +(0pt,23pt) -| ([yshift=3pt]int) arc(90:-90:2.5pt) -- ([xshift=2pt]d.north east);
\end{tikzpicture}

\end{document}

enter image description here

The idea is to use the ubiquitous \tikzmark to place marks for the paths and then to find the intersection of both paths and then draw an arc at the intersection.

The first run of the above code will result in an error:

! Package pgf Error: No shape named intersection-1 is known.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.19 ...{of=line1 and line2,by={int}},draw,->,red]

since the coordinates for the marks are not yet known, so the calculation of the intersection of the paths fails. Quitting the compilation and recompiling, should get the desired result.

In chat, David Carlisle proposed the following modification:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\node[inner xsep=0pt,inner ysep=10pt,outer sep=0pt] (#1) {};%
}

\begin{document}

\[
\tikzmark{c}2:\tikzmark{a}3 + 5:\tikzmark{d}3+\tikzmark{b}2:3+5:3
\]

\expandafter \ifx\csname pgf@sys@pdf@mark@pos@pgfid\the \csname
pgf@picture@serial@count\endcsname\endcsname\relax
\typeout{no}%
\else
\typeout{yes}%
\begin{tikzpicture}[remember picture,overlay]
\draw[name path=line1,red,->] ([xshift=2pt]a.north east) -- +(0pt,10pt) -| ([xshift=2pt]b.north east);
\path[name path=line2] ([xshift=2pt]c.north east) -- +(0pt,23pt) -| ([xshift=2pt]d.north east);
\draw[name intersections={of=line1 and line2,by={int}},draw,->,red] 
  ([xshift=2pt]c.north east) -- +(0pt,23pt) -| ([yshift=3pt]int) arc(90:-90:2.5pt) -- ([xshift=2pt]d.north east);
\end{tikzpicture}
\fi

\end{document}

which doesn't produce errors. The document has to be run three times.

Now percusse has provided this alternative:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\node[inner xsep=0pt,inner ysep=10pt,outer sep=0pt] (#1) {};}

\begin{document}

\[
\tikzmark{c}2:\tikzmark{a}3 + 5:\tikzmark{d}3+\tikzmark{b}2:3+5:3
\]

\begin{tikzpicture}[remember picture,overlay]
\draw[name path=line1,red,->] ([xshift=2pt]a.north east) -- +(0pt,10pt) -| ([xshift=2pt]b.north east);
\path[name path=line2] ([xshift=2pt]c.north east) -- +(0pt,23pt) -| ([xshift=2pt]d.north east);
\path[name intersections={of=line1 and line2,total=\totinter}] \pgfextra{\xdef\totinter{\totinter}};
\ifnum\totinter=0\relax%
\else
\path[name intersections={of=line1 and line2,by={int}}];
  \draw[,draw,->,red] ([xshift=2pt]c.north east) -- +(0pt,23pt) -| ([yshift=3pt]int) arc(90:-90:2.5pt) -- ([xshift=2pt]d.north east);
\fi
\end{tikzpicture}


\end{document}
share|improve this answer
    
The result is perfect! But when I've tried to compile that i've got an error on this line: \path[name intersections={of=line1 and line2,by={int}}]; –  Henrique Apr 13 '13 at 23:37
    
@Henrique sound that you are using an old version of PGF. Please process the following document \documentclass{article} \usepackage{tikz} \begin{document} \pgfversion \end{document} exactly as it is. This will give you your current PGF version. If it's not 2.10, you'll need to updated your packages. –  Gonzalo Medina Apr 13 '13 at 23:39
    
It says that is 2.10 The error: ! Package pgf Error: No shape named intersection-1 is known. –  Henrique Apr 13 '13 at 23:41
    
@Henrique I found the problem. Please see my updated answer. You still need to compile twice to get the right positioning. –  Gonzalo Medina Apr 13 '13 at 23:53
    
After the update, I continue getting the same error. :( –  Henrique Apr 13 '13 at 23:55

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.