2

I am trying to achieve something similar to this:

Cross Multiplication Example

My first idea was to use nodes inside tikzpicture, so I came up with this:

First Example

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning, intersections}
\usepackage{mathtools}
\usepackage{pifont}
\usepackage{xcolor}

\begin{document}
\begin{tikzpicture}
[frac/.style={node distance=-2mm and 8mm}, expression/.style={node distance=2mm and 10mm}]
\node [frac](A) {$3$};
\node [frac](B) [below=of A] {$-$};
\node [frac](C) [below=of B] {$5$};
\node [frac](D) [right=of A] {$5$};
\node [frac](E) [below=of D] {$-$};
\node [frac](F) [below=of E] {$9$};
\node [expression] (exp1) [below=of C] {$3\cdot9=27$};
\node [expression] (exp2) [below=of F] {$5\cdot5=25$};
\draw [<->] (A) -- (F);
\draw [<->] (C) -- (D);
\end{tikzpicture}
\end{document}

Although I like this way of setting up things, the multiplication at the bottom are overlapping and even if (I think) I put 10mm spacing between the nodes, the situation has not improved.

Here the result:

First Example Result

So I've done some research and found this post that, with some modification has served my purpose. This is how I modified it and the end result:

Second Example

\documentclass[border=10pt]{standalone}
\usepackage{tikz,amsmath}
\newcommand\tikzmark[2][]{
  \tikz[remember picture,inner sep=0,outer sep=0,baseline=(#1.base)]{\node(#1){$#2$};}
}


\begin{document}
\begin{tabular}{cc}


$ \dfrac{\tikzmark[topleft]{3}}{\tikzmark[bottomleft]{5}}$ &
    $\dfrac{\tikzmark[topright]{5}}{\tikzmark[bottomright]{9}} $\\
    $3\cdot9=27$ & $5\cdot5=25$\\
\end{tabular}
\begin{tikzpicture} [remember picture,overlay]
    \draw [<->] (topleft) -- (bottomright);
    \draw [<->] (bottomleft) -- (topright);
\end{tikzpicture}

\end{document}

enter image description here

This result is perfect, but the problem is that when I put this code into Anki it does not work, no matter what I put into the preamble of the note type (but I could be doing something wrong).

Not to mention, that I really do not understand its preamble.

In summary, my main question would be: Using nodes as per the first example, how do I avoid the overlapping?

Out of curiosity, I have another question: how can I use tikzmark with Anki, so that I can use the second example?

Thanks!

Ayumu
  • 23

1 Answers1

1

The simpler to do a proper positioning is first to lay out the multiplications and to put the fractions above them.

For the fractions, let amsmath draw them to get a proper size of the bar and vertical spacing. The arrows can be positioned with tikzmarks, but the simpler is just to use the calc library to determine their extremities.

\documentclass[border=10pt]{standalone}
\usepackage{tikz,amsmath}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}[
  every node/.style={inner sep=0}
  ]
  \node (mul1) {$3\cdot9=27$};
  \node[right=5mm of mul1] (mul2) { $5\cdot5=25$};
  \node[above=5mm of mul1] (frac1) {$\dfrac{3}{5}$} ;
  \node[above=5mm of mul2] (frac2) {$\dfrac{5}{9}$} ;
  \draw[<->] ($(frac1.north east)!0.75!(frac1.south east)$)
             -- ($(frac2.north west)!0.25!(frac2.south west)$) ;
  \draw[<->] ($(frac1.north east)!0.25!(frac1.south east)$)
             -- ($(frac2.north west)!0.75!(frac2.south west)$) ;
\end{tikzpicture}
\end{document}

enter image description here

Modify node spacing if required.