
난 그런 걸 하고 싶어:클래스 다이어그램의 교차하지 않는 선
그것으로: http://www.texample.net/tikz/examples/oxyation-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}