在 `TikZ` 环境中的节点中绘制关于分数排版的虚线绿线

在 `TikZ` 环境中的节点中绘制关于分数排版的虚线绿线

在以下TikZ环境中,绘制了三条全等的线段。在第二条线段上,用绿色绘制了一个“X”,在第三条线段上,在第二条线段中与“X”对应的点上方排版了一个分数。

我想在第二和第三条线段上绘制相同的绿色虚线矩形(框),这些矩形的底边应位于线段下方约 0.25 厘米处。

分数是在节点中排版的。为什么 q 的位置比分数线低那么多?

\documentclass[10pt]{amsart}
\usepackage{amssymb}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}


\begin{tikzpicture}[x=0.5cm, y=0.5cm]

%A part of a line is drawn is drawn; ellipses are drawn on both sides of the line segment. Three points on it are labeled.
\draw (-4.5,0) -- (4.5,0);
%
\draw[fill] (-4,0) circle (1.5pt);
\draw[fill] (0,0) circle (1.5pt);
\draw[fill] (4,0) circle (1.5pt);
%
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(-4,0) +(0,0.25)$){$\dfrac{p_{1}}{q_{1}}$};
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(0,0) +(0,0.25)$){$\dfrac{p_{1}+p_{2}}{q_{1}+q_{2}}$};
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(4,0) +(0,0.25)$){$\dfrac{p_{2}}{q_{2}}$};
%
\node[align=center] at (-5.5,0){\ldots};
\node[align=center] at (5.5,0){\ldots};

%An arrow from the display of a quarter of a circle with radius 4 to the display of the removal
%from it a quarter circle with radius 3 is drawn.
\draw[-latex] (-3.5,-3.5) to[out=60,in=120] (-1.5,-3.5);


%A part of a second line is drawn is drawn; ellipses are drawn on both sides of the line segment. Three points on it are labeled,
%and space is made for a fourth point.
\draw (0,-4) -- (11,-4);
%
\draw[fill] (0.5,-4) circle (1.5pt);
\draw[fill] (4.5,-4) circle (1.5pt);
\draw[fill] (10.5,-4) circle (1.5pt);
%
\draw[green] ($(7.5,-4) +(-60:0.5)$) -- ($(7.5,-4) +(120:0.5)$);
\draw[green] ($(7.5,-4) +(-120:0.5)$) -- ($(7.5,-4) +(60:0.5)$);
%
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(0.5,-4) +(0,0.25)$){$\dfrac{p_{1}}{q_{1}}$};
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(4.5,-4) +(0,0.25)$){$\dfrac{p_{1}+p_{2}}{q_{1}+q_{2}}$};
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(10.5,-4) +(0,0.25)$){$\dfrac{p_{2}}{q_{2}}$};
%
\node[align=center] at (-1,-4){\ldots};
\node[align=center] at (12,-4){\ldots};


%An arrow is drawn.
\draw[-latex] (-3.5,-7.5) to[out=60,in=120] (-1.5,-7.5);


%A part of a second line is drawn is drawn; ellipses are drawn on both sides of the line segment. Three points on it are labeled,
%and the fourth point is drawn and labeled.
\draw (0,-8) -- (11,-8);
%
\draw[fill] (0.5,-8) circle (1.5pt);
\draw[fill] (4.5,-8) circle (1.5pt);
\draw[fill] (10.5,-8) circle (1.5pt);
%
\draw[fill] (7.5,-8) circle (1.5pt);
%
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(0.5,-8) +(0,0.25)$){$\dfrac{p_{1}}{q_{1}}$};
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(4.5,-8) +(0,0.25)$){$\dfrac{p_{1}+p_{2}}{q_{1}+q_{2}}$};
\node[anchor=south, inner sep=0, font=\footnotesize] at ($(10.5,-8) +(0,0.25)$){$\dfrac{p_{2}}{q_{2}}$};
%
\node[anchor=south, inner sep=0, green, font=\footnotesize] at ($(7.5,-8) +(0,0.25)$){$\dfrac{p}{q}$};
%
\node[align=center] at (-1,-8){\ldots};
\node[align=center] at (12,-8){\ldots};


\end{tikzpicture}

\end{document}

答案1

我添加了一种样式,可让您更轻松地绘制项目符号-分数组合。此样式根据节点的名称命名标签,但将一个放在-l末尾。然后,您可以通过以下方式在项目符号-分数组合周围绘制框:

\node[gfit=p31];

providep31是该组合的名称。

\documentclass[10pt]{amsart}
\usepackage{amssymb}

\usepackage{tikz}
\usetikzlibrary{calc,shapes.misc,fit}
\makeatletter
\tikzset{cnode/.style={circle,fill,inner sep=1.5pt,
/utils/exec=\xdef\myname{\tikz@fig@name},
label={[font=\footnotesize,alias=\myname-l]above:#1},
node contents={}}}
\makeatother

\begin{document}


\begin{tikzpicture}[x=0.5cm, y=0.5cm,gfit/.style={green,dashed,draw,inner
xsep=1pt,fit=(#1)(#1-l),node contents={}}]

%A part of a line is drawn is drawn; ellipses are drawn on both sides of the line segment. Three points on it are labeled.
\draw (-4.5,0) node[left]{\ldots} -- (4.5,0)node[right]{\ldots};
%
\path (-4,0) node (p11) [cnode={$\dfrac{p_{1}}{q_{1}}$}]
++(4,0) node (p12) [cnode={$\dfrac{p_{1}+p_{2}}{q_{1}+q_{2}}$}]
++(4,0) node (p13) [cnode={$\dfrac{p_{2}}{q_{2}}$}];

%An arrow from the display of a quarter of a circle with radius 4 to the display of the removal
%from it a quarter circle with radius 3 is drawn.
\draw[-latex] (-3.5,-3.5) to[out=60,in=120] (-1.5,-3.5);


%A part of a second line is drawn is drawn; ellipses are drawn on both sides of the line segment. Three points on it are labeled,
%and space is made for a fourth point.
\draw (0,-4) node[left]{\ldots} -- (11,-4) node[right]{\ldots};
%
\path (0.5,-4) node (p21) [cnode={$\dfrac{p_{1}}{q_{1}}$}]
++(4,0) node (p22) [cnode={$\dfrac{p_{1}+p_{2}}{q_{1}+q_{2}}$}]
++(6,0) node (p23) [cnode={$\dfrac{p_{2}}{q_{2}}$}]
(7.5,-4) node[cross out,draw,inner sep=1ex,green]{};
%

%An arrow is drawn.
\draw[-latex] (-3.5,-7.5) to[out=60,in=120] (-1.5,-7.5);


%A part of a second line is drawn is drawn; ellipses are drawn on both sides of the line segment. Three points on it are labeled,
%and the fourth point is drawn and labeled.
\draw (0,-8) node[left]{\ldots} -- (11,-8) node[right]{\ldots};
%
\path (0.5,-8) node (p31) [cnode={$\dfrac{p_{1}}{q_{1}}$}]
++(4,0) node (p32) [cnode={$\dfrac{p_{1}+p_{2}}{q_{1}+q_{2}}$}]
++(6,0) node (p33) [cnode={$\dfrac{p_{2}}{q_{2}}$}]
(7.5,-8) node[circle,fill,inner sep=1.5pt,label={[green,name=X-l]above:{$\dfrac{p}{q}$}}]
(X){};
%
\node[gfit=p31];
\end{tikzpicture}

\end{document}

在此处输入图片描述

q 与分数线的距离与 Ti 无关Z. 例如,您可以使用\raisebox将 q 向上抬起。

相关内容