tikz-pgf – How to Illustrate Double Distributive Property in LaTeX

tikz-arrowstikz-pgftikz-styles

enter image description here

$\left(a+b\right)\left(c+d\right)=ac+ad+bc+bd$

Best Answer

Here's a solution using tikzmark library, instead of reinventing the wheel, like many old solutions you can find here.

tikzmark ditributivity

\documentclass[12pt]{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{tikzmark}

\begin{document}
    \tikzset{
        every node/.style={outer sep=1pt},
        num/.style={draw,circle,fill=white,font=\tiny,inner sep=1pt}}
    
    \[
    (\tikzmarknode{A}{a}+\tikzmarknode{B}{b})(\tikzmarknode{C}{c}+\tikzmarknode{D}{d})=\tikzmarknode{AC}{ac}+\tikzmarknode{AD}{ad}+\tikzmarknode{BC}{bc}+\tikzmarknode{BD}{bd}
    \]
    
    \begin{tikzpicture}[remember picture, overlay,cyan]
        \draw[->] (A) to[out=60,in=100,looseness=1.5] node[num,pos=0.5] {1} (C) ;
        \draw[->] (A) to[out=60,in=110,looseness=1.8] node[num,pos=0.5] {2} (D) ;
        
        \draw[->] (B) to[out=-90,in=-100,looseness=1.6] node[num,pos=0.5] {3} (C) ;
        \draw[->] (B) to[out=-90,in=-110,looseness=1.9] node[num,pos=0.5] {4} (D) ;

        \foreach \n [count=\i] in {AC,AD,BC,BD}
            \node[num,above=10pt] at (\n.south) {\i};
    \end{tikzpicture}
\end{document}
Related Question