
quiero hacer algo asi:Líneas que no se cruzan en el diagrama de clases
con ese: http://www.texample.net/tikz/examples/oxidation-and-reduction/
Será algo como:
Respuesta1
Aquí hay una posibilidad de usar la intersections
biblioteca deTikZ
:
\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}
La idea es utilizar lo omnipresente \tikzmark
para colocar marcas en los caminos y luego encontrar la intersección de ambos caminos y luego dibujar un arco en la intersección.
La primera ejecución del código anterior generará un 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]
Dado que aún no se conocen las coordenadas de las marcas, el cálculo de la intersección de los caminos falla. Salir de la compilación y volver a compilarla debería obtener el resultado deseado.
En el chat,David Carlislepropuso la siguiente modificación:
\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}
que no produce errores. El documento debe ejecutarse tres veces.
Ahorapercutirha proporcionado esta alternativa:
\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}