2

Recently I've made a question which I ask how could I make a common factor scheme, and someone makes it works. But now, it has unformatted my other expression. Could someone help me?

The code:

\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{calc}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBox}[2]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[->,shorten >=5pt,shorten <=5pt,out=70,in=130,distance=0.5cm,#1] (MarkA.north) to (MarkC.north);
    \draw[->,shorten >=5pt,shorten <=5pt,out=50,in=140,distance=0.3cm,#2] (MarkA.north) to (MarkB.north);
  \end{tikzpicture}
}

\begin{document}
    \[
        (\tikzmark{a}ax + \tikzmark{b}ay) = \tikzmark{c}a(x + y)
        \tikz[remember picture, overlay, baseline=0pt] {
            \draw[red, thick] ($(pic cs:a) + (0.1, 0.2)$) to[out=90, in=90] ($(pic cs:c) + (0.1, 0.2)$);
            \draw[red, thick] ($(pic cs:b) + (0.1, 0.2)$) to[out=90, in=90] ($(pic cs:c) + (0.1, 0.2)$);
        }
    \]
    
    \[\tikzmark{MarkA}a(b\tikzmark{MarkB}+c\tikzmark{MarkC})=ab+ac \DrawBox{OrangeRed}{Cerulean}\]

\begin{align*}
-(2x+5)&=(-\tikzmark{MarkA}1)(2x\tikzmark{MarkB}+5\tikzmark{MarkC})\DrawBox{OrangeRed}{Cerulean}\\
       &=(-1)(2x)+(-1)(5)\\
       &=-2x+(-5)\\
       &=-2x-5
\end{align*}
\end{document} 

The output: enter image description here

(The purpose of the second part is to explicit the distributive property)

1
  • 2
    When loading the tikzmark library, don't use \newcommand\tikzmark... in addition. Because the library already defines a macro by that name, you get an error. Mar 31, 2021 at 21:22

1 Answer 1

5

A very quick answer. Your LaTeX distribution seems to be old. The tikzmark library has evolved and now provides various different commands, especially the \tikzmarknode which you may want to use, here.
I didn't change anything to your first line (you can copy/paste what I did for the rest). Feel free to try some other numbers for the in, out and looseness controls of the arrows.

tikzmark to distribute

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{calc}
\usepackage{amsmath}
\usetikzlibrary{calc,shapes}

\newcommand{\DrawBox}[2]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[->,shorten >=2pt,shorten <=2pt,out=80,in=100,looseness=1.5,#1] (MarkA.north) to (MarkC.north);
    \draw[->,shorten <=2pt,out=80,in=100,looseness=2,#2] (MarkA.north) to (MarkB.north);
  \end{tikzpicture}
}

\begin{document}
    \[
        (\tikzmarknode{a}{ax} + \tikzmarknode{b}{ay}) = \tikzmarknode{c}{a}(x + y)
        \tikz[remember picture, overlay, baseline=0pt] {
            \draw[red, thick] ($(pic cs:a) + (0.1, 0.2)$) to[out=90, in=90] ($(pic cs:c) + (0.1, 0.2)$);
            \draw[red, thick] ($(pic cs:b) + (0.1, 0.2)$) to[out=90, in=90] ($(pic cs:c) + (0.1, 0.2)$);
        }
    \]
    
    \[\tikzmarknode{MarkA}{a}(\tikzmarknode{MarkB}{b}+\tikzmarknode{MarkC}{c})=ab+ac \]
    \DrawBox{orange}{cyan}

\begin{align*}
-(2x+5)&=(\tikzmarknode{MarkA}{-1})(\tikzmarknode{MarkB}{2x}+\tikzmarknode{MarkC}{5})\\
       &=(-1)(2x)+(-1)(5)\\
       &=-2x+(-5)\\
       &=-2x-5
\end{align*}
\DrawBox{orange}{cyan}
\end{document} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .