2

In the following TikZ environment, three congruent line segments are drawn. On the second line segment, an "X" is drawn in green, and on the third line segment, a fraction is typeset above the point corresponding to the "X" in the second line segment.

I would like to draw identical dashed, green rectangles (boxes) about these corresponding points on the second and third line segments. The bottom edge of the rectangles should be about 0.25cm below the line segments.

Fractions are typeset in the nodes. Why are the q's positioned so far below the fraction bar?

\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
    You mean just \draw [green,dashed] (7, -3.5) rectangle (8,-8.5); or similar? Your last question is more of a math-mode question than a tikz-pgf question. I guess it's simply that there's room on the line for upper case characters. – Torbjørn T. Oct 10 '19 at 16:59
1

I added a style that allows you to draw the bullet-fraction combination more easily. This style names the label according to the name of the node but puts an -l in the end. Then you can draw boxes around the bullet-fraction combinations by saying

\node[gfit=p31];

provide p31 is the name of that combination.

\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}

enter image description here

The distance of q from the fraction line is not related to TikZ. You could e.g. use \raisebox to lift the q up.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.