聚合 tikz

聚合 tikz

最近我问了一个问题,我问如何制作一个公因数方案,有人让它起作用了。但是现在,它已经格式化了我的其他表达式。有人能帮帮我吗?

代码:

\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} 

输出: 在此处输入图片描述

(第二部分的目的是明确分配律)

答案1

一个非常快速的回答。您的 LaTeX 发行版似乎很旧。该tikzmark库已经发展,现在提供各种不同的命令,特别是\tikzmarknode您可能想要使用的命令。
我没有对您的第一行进行任何更改(您可以复制/粘贴我对其余部分所做的更改)。请随意尝试一些其他数字作为in箭头的out和控件。looseness

tikzmark 分发

\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} 

相关内容