连接文本和图形

连接文本和图形

这个想法被厚颜无耻地窃取自:http://www.texample.net/tikz/examples/connecting-text-and-graphics/

这是我的 MWE:

\documentclass{article}

\usepackage{tikz,tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{arrows,shapes,backgrounds}
\begin{document}
\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [baseline=-.5ex]

Nec no appareat persecuti \tikz[na] \coordinate (s-anode);, ea meis labitur honestatis nec. 

Nisl indoctum delicatissimi ad nam, adolescens intellegam dissentiet pri no, facete assueverit in nam. Sed ne odio tale suscipit, ex vide rationibus percipitur mea. Ea diceret periculis dissentiet nam, ne duo novum graece. 

\begin{figure}[!h]
\begin{tikzpicture}[scale=1]
        \tkzInit[xmin=-0.5, xmax=5.5, ymin=-0.9, ymax=3.5]
        \tkzClip
        \tkzDefPoints{0/0/C, 3/3/A, 5/0/B, 1/3/a, 5/3/b}
        \tkzLabelPoint[above](A){$A$}
        \tkzLabelPoint[below right](B){$B$}
        \tkzLabelPoint[below left](C){$C$}
        \draw (1,3.2) node {\textit{Euclides' line}};
        \tkzLabelAngle[pos=-0.8](a,A,C){$1$}
        \tkzMarkAngle[size=0.5](a,A,C)
        \tkzMarkAngle[size=0.5](B,C,A)
        \tkzLabelAngle[pos=0.7](b,A,B){$2$}
        \tkzMarkAngle[arc=ll,size=0.5 cm](B,A,b)
        \tkzMarkAngle[arc=ll,size=0.5 cm](A,B,C)
        \tkzDrawPolygon[very thick](A,B,C)
        \tkzDrawLine[add=1 and 1](A,a)
        \tkzDrawPoints(A,B,C)
        \path[->,red,thick] (s-anode) edge [bend left] (C);
        \end{tikzpicture}
\end{figure}
\end{document}

它运行正常(至少在我的计算机上)并且产生了如下结果: 在此处输入图片描述

明显地,

    \tkzInit[xmin=-0.5, xmax=5.5, ymin=-0.9, ymax=3.5]
    \tkzClip

破坏了箭头。在我评论它之后,它也能工作,但会产生以下结果: 在此处输入图片描述

原因很明显:tkz-euclide需要一些空间用于构造,并且这个空间应该被切断(据我所知)。但这条线仍然没有超出图片。所以这个(\tkzClip)不是原因。我做错了什么?我想将文本中的一个随机单词与图表上的一个随机点连接起来(如链接中所示)。谢谢。

答案1

最简单的方法是将箭头放在单独的图片中。您需要overlay图片的选项,如示例所示,但您不希望将其放在主图片中。

请注意已弃用,仅与选项一起\tikzstyle使用是不明智的(并且可能无效 - 它仅表示“如果可能,在这里”)。如果您需要标题,请使用from或。figureh\captionofcaptioncapt-of

\documentclass{article}
\usepackage{tikz,tkz-euclide,caption}
\usetkzobj{all}
\usetikzlibrary{arrows,shapes,backgrounds}
\begin{document}
\tikzset{% \tikzstyle is deprecated
  every picture/.append style={remember picture},
  na/.style = {baseline=-.5ex},
}

Nec no appareat persecuti \tikz[na] \coordinate (s-anode);, ea meis labitur honestatis nec.

Nisl indoctum delicatissimi ad nam, adolescens intellegam dissentiet pri no, facete assueverit in nam. Sed ne odio tale suscipit, ex vide rationibus percipitur mea. Ea diceret periculis dissentiet nam, ne duo novum graece.

\begin{center}
  \begin{tikzpicture}
    \tkzInit[xmin=-0.5, xmax=5.5, ymin=-0.9, ymax=3.5]
    \tkzClip
    \tkzDefPoints{0/0/C, 3/3/A, 5/0/B, 1/3/a, 5/3/b}
    \tkzLabelPoint[above](A){$A$}
    \tkzLabelPoint[below right](B){$B$}
    \tkzLabelPoint[below left](C){$C$}
    \draw (1,3.2) node {\textit{Euclides' line}};
    \tkzLabelAngle[pos=-0.8](a,A,C){$1$}
    \tkzMarkAngle[size=0.5](a,A,C)
    \tkzMarkAngle[size=0.5](B,C,A)
    \tkzLabelAngle[pos=0.7](b,A,B){$2$}
    \tkzMarkAngle[arc=ll,size=0.5 cm](B,A,b)
    \tkzMarkAngle[arc=ll,size=0.5 cm](A,B,C)
    \tkzDrawPolygon[very thick](A,B,C)
    \tkzDrawLine[add=1 and 1](A,a)
    \tkzDrawPoints(A,B,C)
  \end{tikzpicture}%
  \begin{tikzpicture}[overlay]
    \path[->,red,thick] (s-anode) edge [bend left] (C);
  \end{tikzpicture}
  \captionof{figure}{Caption}
\end{center}
\end{document}

重叠箭头

请注意,该tikz-mark\tikzmark{}为此目的提供了子节点。

答案2

末尾的红色箭头tikzpicture需要选项overlay。否则 TikZ 会将坐标考虑为图片的边界框。

可以通过范围来限制剪辑:

\documentclass{article}
\usepackage{tikz,tkz-euclide,caption}
\usetkzobj{all}
\begin{document}
\tikzset{% \tikzstyle is deprecated
  every picture/.append style={remember picture},
  na/.style = {baseline=-.5ex},
}

Nec no appareat persecuti\tikz[na]\coordinate(s-anode);,
ea meis labitur honestatis nec.

Nisl indoctum delicatissimi ad nam, adolescens intellegam dissentiet pri no,
facete assueverit in nam.  Sed ne odio tale suscipit, ex vide rationibus
percipitur mea.  Ea diceret periculis dissentiet nam, ne duo novum graece.

\begin{center}
  \begin{minipage}{\linewidth}
    \centering
    \begin{tikzpicture}
      \tkzInit[xmin=-0.5, xmax=5.5, ymin=-0.9, ymax=3.5]
      \begin{scope}
        \tkzClip
        \tkzDefPoints{0/0/C, 3/3/A, 5/0/B, 1/3/a, 5/3/b}
        \tkzLabelPoint[above](A){$A$}
        \tkzLabelPoint[below right](B){$B$}
        \tkzLabelPoint[below left](C){$C$}
        \draw (1,3.2) node {\textit{Euclides' line}};
        \tkzLabelAngle[pos=-0.8](a,A,C){$1$}
        \tkzMarkAngle[size=0.5](a,A,C)
        \tkzMarkAngle[size=0.5](B,C,A)
        \tkzLabelAngle[pos=0.7](b,A,B){$2$}
        \tkzMarkAngle[arc=ll,size=0.5 cm](B,A,b)
        \tkzMarkAngle[arc=ll,size=0.5 cm](A,B,C)
        \tkzDrawPolygon[very thick](A,B,C)
        \tkzDrawLine[add=1 and 1](A,a)
        \tkzDrawPoints(A,B,C)
      \end{scope}
      \path[overlay,->,red,thick] (s-anode) edge [bend left] (C);
    \end{tikzpicture}
    \captionof{figure}{Caption}
  \end{minipage}
\end{center}
\end{document}

结果

相关内容