
Я хочу сделать что-то вроде этого:Непересекающиеся линии на диаграмме классов
с этим: http://www.texample.net/tikz/examples/oxidation-and-reduction/
Это будет что-то вроде:
решение1
Вот одна из возможностей использования intersections
библиотеки из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}
Идея состоит в том, чтобы использовать вездесущие \tikzmark
метки для путей, а затем найти пересечение обоих путей и нарисовать дугу на пересечении.
Первый запуск приведенного выше кода приведет к ошибке:
! 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]
поскольку координаты для меток пока неизвестны, то расчет пересечения путей не удается. Выход из компиляции и повторная компиляция должны дать желаемый результат.
В чате,Дэвид Карлайлпредложил следующую поправку:
\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}
который не выдает ошибок. Документ должен быть запущен три раза.
Сейчасударныепредоставил такую альтернативу:
\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}