7

I want to circle the "second half" of a fraction in an equation, like this:

I want to circle y_1 and x_1

However, after hours of searching, I'm still unable to do this seemingly simple task.
The current state of my code:

\documentclass{article}

\usepackage{mathtools}

% Circling
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
        \node[shape=circle,draw,inner sep=1pt] (char) {#1};}}

\begin{document}
    \begin{equation*}
        {m} = \frac{y_2 - y_1}{x_2 - x_1}
    \end{equation*}
\end{document}

I managed to circle individual parts of the equation with the 'circled' command, but I was unable to reproduce the image above.

Thanks for any advice!

werck
  • 73

3 Answers3

7

Another solution with pstricks:

\documentclass[svgnames]{article}

\usepackage{mathtools}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{equation*}
    \begin{postscript}
        m = \frac{y_2 -\pnode[0,1.75ex]{N} y_1}{x_2 -x_1 \pnode[0.25ex,-1ex]{D}}
        \psframe[linecolor=IndianRed, linewidth=0.5pt, framearc=0.5](N)(D)
    \end{postscript}
\end{equation*}

\end{document}

enter image description here

Bernard
  • 271,350
  • Do you like football? True? :-) Perfect. – Sebastiano Aug 12 '18 at 20:24
  • @Sebastiano: No, I don't like football! B. t.w. did you solve your problem updating MiKTeX? – Bernard Aug 12 '18 at 20:26
  • Bernard. I'm still updating MikTeX :-( I have to wait at least half an hour to install it and then I have to load additional fonts. That's bad luck every time. Frankly, I haven't really liked football for at least 8 years. – Sebastiano Aug 12 '18 at 20:29
  • @Bernard : the box looks bad, not exactly vertical. I guess there is a \phantom{x_1} to be added somewhere near y_1 in order to have same dimensions on denominator and numerator. I'm not capable to suggest a fix. – pzorba75 Aug 13 '18 at 03:16
  • 1
    @pzorba75: You're right. This is due to the difference in width of x and y, so the centres of the \Rnodes are not vertically aligned. As it also involves the beginning of the numerator and the denominator, I don't see how to fix it, so I preferred to replace \ncbox with a simple psframe – which makes the code a bit simpler. – Bernard Aug 13 '18 at 09:36
  • You have written \begindocument instead of \begin{document} – F. Pantigny Aug 13 '18 at 09:48
  • @F.Pantigny: Oh! yes. I've fixed it. Thanks! – Bernard Aug 13 '18 at 10:11
6

You could use the tikzmark library. It has the advantage of not disturbing the typesetting of the equation too much.

Sample output

\documentclass{article}

\usepackage{mathtools,tikz}
\usetikzlibrary{tikzmark,calc}

\begin{document}

\begin{equation*}
  {m} = \frac{y_2 - \tikzmark{top}y_1}{x_2 - \tikzmark{bot}x_1}
\end{equation*}
\tikz[remember picture]{\draw[overlay,red] ($(pic cs:top)!.5!(pic
cs:bot)+(.4em,.2em)$) circle[x radius=1em,y radius=2em];}

\end{document}
Andrew Swann
  • 95,762
  • As I was already using the tikz package for the rest of the document, this solution is very convenient, so I'm going to accept this one as the solution. Thank you very much! – werck Aug 13 '18 at 17:34
4

My English language is bad :-). I hope to solve your question. With [yscale=2] you have an ellipse with the foci on axes y, and with

\draw (1.2,2.7) circle (.4);

you can place the ellipse as you want by increasing or decreasing the eccentricity.

enter image description here

\documentclass[12pt]{article}
\usepackage{pgf,tikz,pgfplots}
\usepackage{mathrsfs}
\usepackage{mathtools}

\begin{document}
\begin{tikzpicture}[yscale=2]
\draw (-1,3) node[anchor=north west] {$m=\dfrac{y_2-y_1}{x_2-x_1}$};
\draw (1.2,2.7) circle (.4);
\end{tikzpicture}

\end{document}
Sebastiano
  • 54,118