6

How can I turn the yellow shaded area into an opaque shaded 1 to demonstrate the idea of an equivalent fraction?

\documentclass{article}
\usepackage{tikz,amsmath,xcolor}

\begin{document}
\[ \begin{tikzpicture}
         \node at (0,0) {$\dfrac{a \cdot c}{b \cdot c}=\color{blue}\underbrace{\color{black}{}\dfrac{a}{b} \cdot \colorbox{yellow}{$\dfrac{c} 
{c}$}}}\color{black}{}=\dfrac{a}{b}$};
         \draw[->,blue] (.2,-.5)--(.2,-.7)--(1.2,-.7)--(1.2,-.3);
         \node at (.2,-.7) [below right] {\scriptsize $\color{blue}{\text{Since}\ \dfrac{a}{b} \cdot 1 =\dfrac{a}{b}}$}; 
\end{tikzpicture} \]

\end{document}

enter image description here

To look like this :

enter image description here

And eventually being able to look like this:

enter image description here

MathScholar
  • 2,513

2 Answers2

7

I was confused by the various versions of the question. This made my answer look very complicated. However, this is because the answer (which I kept below) would clip the formula against the contour of 1 or whatever. Now that I see that the accepted answer does not have any of these features, I also provide a stripped down version, which has the big advantage (IMHO) that you do not have to adjust tons of dimensions.

\documentclass{article}
\usepackage{tikz,amsmath,pifont}
\usetikzlibrary{backgrounds}
\newcommand{\PlaceCharOverSomething}[3][xscale=11,yscale=5]{%
\tikz[baseline=(X.base)]{
\node[opacity=0] (tmpX){#3};
\begin{scope}[on background layer]
\clip (tmpX.south west) rectangle  (tmpX.north east);
\node[overlay,outer sep=0pt,text=blue!,opacity=0.3,#1]
{\bfseries\sffamily #2};
\end{scope}
\node [inner sep=0pt](X){#3};}%
}
\begin{document}
\[ 
\dfrac{a \cdot c}{b \cdot c}=
\textcolor{blue}{\underbrace{\textcolor{black}{\dfrac{a}{b} \cdot}
\PlaceCharOverSomething{\ding{192}}{$\dfrac{c}{c}$}
}_{\tikz[remember picture]{\coordinate(b);}}}
=\tikz[remember picture,baseline=(Y.base)]{\node (Y) {$\dfrac{a}{b}$};}
\]
\tikz[remember picture,overlay]{\draw[->,blue] ([yshift=1mm]b)--++(0,-0.2)
-|(Y) node[pos=0.25,below]{since $\frac{a}{b}\cdot1=\frac{a}{b}$};}
\end{document}

enter image description here

Also the wide shape is no problem.

\documentclass{article}
\usepackage{tikz,amsmath,pifont}
\usetikzlibrary{backgrounds}
\newcommand{\PlaceCharOverSomething}[3][xscale=51,yscale=6]{%
\tikz[baseline=(X.base)]{
\node[opacity=0] (tmpX){#3};
\begin{scope}[on background layer,overlay]
\clip ([xshift=-1mm]tmpX.south west) rectangle  (tmpX.north east);
\node[overlay,outer sep=0pt,text=cyan,opacity=0.3,#1]
{\bfseries\sffamily #2};
\end{scope}
\node [inner sep=0pt](X){#3};}%
}
\begin{document}
\[ 
\dfrac{a \cdot c}{b \cdot c}=
\textcolor{blue}{\underbrace{\textcolor{black}{\dfrac{a}{b} \cdot}
\PlaceCharOverSomething{\ding{192}}{\textcolor{black}{$\dfrac{x-3}{x-3}$}}
}_{\tikz[remember picture]{\coordinate(b);}}}
=\tikz[remember picture,baseline=(Y.base)]{\node (Y) {$\dfrac{a}{b}$};}
\]
\tikz[remember picture,overlay]{\draw[->,blue] ([yshift=1mm]b)--++(0,-0.2)
-|(Y) node[pos=0.25,below]{since $\frac{a}{b}\cdot1=\frac{a}{b}$};}
\end{document}

enter image description here

Now comes a proposal based on this answer and that answer, which allows you to clip a formula against a shape. You may play with xscale, yscale etc. If you make the fraction a node, all tikz options are available. BTW, do not use \color, use \textcolor instead. And very soon there will be an upgrade of the tikzmark library available, which will simplify such things quite a bit.

\documentclass{article}
\usepackage{tikz,amsmath,pifont}
\usetikzlibrary{fadings,backgrounds}
\usepackage{contour}
\newcommand{\PlaceCharOverSomething}[3][xscale=11,yscale=5]{%
\renewcommand*\sfdefault{ugq}
\begin{tikzfadingfrompicture}[name=temp]
\node[transparent!0,#1] 
{\contour{black}{\bfseries\sffamily\textcolor{white}{#2}}};
\end{tikzfadingfrompicture}%
\tikz[baseline=(X.base)]{
\node[opacity=0] (tmpX){#3};
\begin{scope}[on background layer]
\clip (tmpX.south west) rectangle  (tmpX.north east);
\node[overlay,outer sep=0pt,text=blue!,opacity=0.3,#1]
{\bfseries\sffamily #2};
\end{scope}
\path[path fading=temp,fit fading=false,overlay,inner sep=0pt] node (X){#3};
\path (X.west) -- (X.east);
\path (X.north) -- (X.south);}%
}
\begin{document}
\[ 
\dfrac{a \cdot c}{b \cdot c}=
\textcolor{blue}{\underbrace{\textcolor{black}{\dfrac{a}{b} \cdot}
\PlaceCharOverSomething{\ding{192}}{$\dfrac{c}{c}$}
}_{\tikz[remember picture]{\coordinate(b);}}}
=\tikz[remember picture,baseline=(Y.base)]{\node (Y) {$\dfrac{a}{b}$};}
\]
\tikz[remember picture,overlay]{\draw[->,blue] ([yshift=1mm]b)--++(0,-0.2)
-|(Y) node[pos=0.25,below]{since $\frac{a}{b}\cdot1=\frac{a}{b}$};}
\end{document}

enter image description here

Note that, because I am using TikZ, there are certain things that come for free.

  • I do not have manually adjust any dimensions. In particular, the fraction sits precisely where it would sit without this brimborium. However, if you want, you can make the node wider, e.g. by replacing \path (X.west) -- (X.east); by \path ([xshift=-1pt]X.west) -- (X.east[xshift=1pt]);. I consider the fact that I do not have to finetune the dimensions a big advantage.
  • Similarly, the arrow is fully fixed by the elements of the formula. All the dimensions of \draw[->,blue] (.2,-.5)--(.2,-.7)--(1.2,-.7)--(1.2,-.3); get redundant, the only thing I specify in \draw[->,blue] ([yshift=1mm]b)--++(0,-0.2) -|(Y); is an yshift which makes the arrow start a bit higher up (I actually merely added this to show you how to adjust these things if you really want to) and -0.2 which just says that the arrow needs to go down by 0.2cm before connecting to the fraction on the right. If you add something before the fraction on the right, the arrow will auto-adjust.
  • This path fading is extremely powerful since it allows you to cut things off that run out of the character. Although not needed here, this is something that may me used in future applications of these tricks.
  • Needless to say that, if you decide that the fraction c/c should also come with a certain opaqueness or color, this would only require a simple switch.
  • I have been using tikzmarknode more frequently now. How can I make that area( node ) you posted a 1 instead of an opaque yellow rectangle. What you posted is much cleaner for sure. This is the heart of my question. – MathScholar Oct 01 '18 at 22:40
  • @MathScholar I do not understand your question. If you want a 1 instead of an opaque rectangle with a fraction in it, replace \tikz[baseline=(X.base)]{\node[fill=yellow,opacity=0.5](X){$\dfrac{c}{c}$};} by 1. And yes, \tikzmarknode will make this easier. Note, however, the opaque stuff does not really get referenced later here, so for this thingy you do not need a \tikzmarknode, but for the other two thingies \tikzmark and \tikzmarknode will be more elegant. –  Oct 01 '18 at 22:45
  • How can I make that opaque area have the shape of a 1, the number one, while leaving the $\dfrac{c}{c}$ as is ? I am not sure how to post an image in the comment section. – MathScholar Oct 01 '18 at 22:50
  • I added an image of what I am trying to replicate. Thanks for your efforts – MathScholar Oct 01 '18 at 23:07
  • I noticed that the character 1 is pushing out the product while compiling your solution. – MathScholar Oct 01 '18 at 23:48
  • @MathScholar I added an overlay solution. –  Oct 01 '18 at 23:54
  • That looks much better Marmot. I have to stop tonight and come back in the morning. Thanks for your help – MathScholar Oct 02 '18 at 00:33
  • These look exceptional! I will look at these in the morning. Thanks Marmot – MathScholar Oct 02 '18 at 02:30
  • I have both programs working. I assume the character is \ding{192}. I would have never been able to program on my own and need to read through the manuals to understand the mechanics. I guess the next step I could ask and it may be a separate question: Cross multiplication arrows. How could I create opaque arrows to demonstrate cross-multiplication to a student? That would be beyond the call of duty! – MathScholar Oct 02 '18 at 16:01
  • @MathScholar \ding{192} is just a trick to get the arguably nicer 1. And yes, it would be better to ask a new question. Questions are free. And if someone else is just curious about one aspect, (s)he may get very confused when there are tons of things around. –  Oct 02 '18 at 16:05
4

With stackengine.

\documentclass{article}
\usepackage{tikz,amsmath,xcolor,stackengine}

\begin{document}
\[ \begin{tikzpicture}
         \node at (0,0) {$\dfrac{a \cdot c}{b \cdot c}=\color{blue}%
  \underbrace{\color{black}{}\dfrac{a}{b} \cdot 
  \stackengine{0pt}{\makebox[0pt]{\raisebox{-10pt}{\scalebox{10}[8]{%
    \color{blue!20}\sffamily\tiny 1}}}}{$\dfrac{c}{c}$}{O}{c}{F}{F}{L}}%
  \color{black}{}=\dfrac{a}{b}$};
         \draw[->,blue] (.2,-.5)--(.2,-.7)--(1.2,-.7)--(1.2,-.3);
         \node at (.2,-.7) [below right] {\scriptsize $\color{blue}{%
  \text{Since}\ \dfrac{a}{b} \cdot 1 =\dfrac{a}{b}}$}; 
\end{tikzpicture} \]

\end{document}

enter image description here

  • I guess if you could get rid of the feet on that 1 we have a perfect match. Thanks for your post I am using yours and Marmot's tikzmarknode. Never heard of stackengine – MathScholar Oct 02 '18 at 00:10
  • @MathScholar I tried to find an appropriate font for the "1", but was not immediately successful. Once the font is done, just put the \fontfamily...\selectfont into that argument of stackengine. – Steven B. Segletes Oct 02 '18 at 00:12
  • @MathScholar https://ctan.org/pkg/stackengine, https://ctan.org/pkg/tabstackengine – Steven B. Segletes Oct 02 '18 at 00:13
  • Another concern I have is the "fatness" of '1' for example if c is 100/100 then the 1 is not fat enough. Looks like it is not an easy question. Thank you Steven – MathScholar Oct 02 '18 at 00:23
  • @MathScholar The \scalebox{10}[8]{...} gives a horizontal scale of 10 and a vertical scale of 8, so some games can be played. However, with enough digits, like 100/100, even that has its limits. – Steven B. Segletes Oct 02 '18 at 00:30
  • @StevenB.Segletes I believe to have found a font that resembles the OP's screen shot very closely.... –  Oct 02 '18 at 02:16