画箭头表示乘法模式(分配律)

画箭头表示乘法模式(分配律)

基于这个问题:如何在等式各部分之间画箭头来显示数学分配律(乘法)?我得到了一些很好的工具来向我的学生说明如何找到数字或变量与括号的乘积。

但是,当我需要在一行中有两个源时,例如在扩展时,解决方案就会失败(a+3)(b+4)。我还可以在箭头旁边或上方放置一个小数字,以指示第一个计算、第二个计算等。第二组箭头也可以位于表达式下方,而不是上方,以简化事情。

我当然可以自己定义一组类似于现有宏的新宏,例如\sourceTwo\targetTwo,但感觉可以做得更优雅。

梅威瑟:

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\newcommand\source[1]{%
    \tikz[remember picture,baseline,inner sep=0pt] {%
        \node [name=source,anchor=base]{$#1$};
    }%
    \setcounter{target}{0}
}
\newcounter{target}
\newcommand\target[1]{%
    \tikz[remember picture,baseline,inner sep=0pt] {%
        \node [name=target-\thetarget,anchor=base]{$#1$};
    }%
    \stepcounter{target}%
}
\newcommand\drawarrows{
    \tikz[remember picture, overlay, bend left=45, -latex] {
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw (source.north) to (target-\n.north);
        }
    }
}

\begin{document}

\begin{equation}
    (\source{a}+4)(\target{b}+\target{3}) = \drawarrows
\end{equation}

\end{document}

答案1

以下代码可能是您的起点:

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\newcounter{source}
\newcommand\source[1]{%
    \tikz[remember picture,baseline,inner sep=0pt] {%
        \node [name=source-\thesource,anchor=base]{$#1$};
    }%
    \setcounter{target}{0}
    \stepcounter{source}
}

\newcounter{target}
\newcommand\target[1]{%
    \tikz[remember picture,baseline,inner sep=0pt] {%
        \node [name=target-\thetarget,anchor=base]{$#1$};
    }%
    \setcounter{source}{0}
    \stepcounter{target}%
}
\newcommand\drawarrows{
    \tikz[remember picture, overlay, bend left=45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [red](source-0.north) to (target-\n.north) coordinate (UP);
          }
       \node [red] at (UP) [above] {1}; 
    }
}

 \tikz[remember picture, overlay, bend left=-45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [blue](source-1.south) to (target-\n.south) coordinate (DOWN) ;
         }
        \node [blue] at (DOWN) [below] {2};
    }
}
}



\begin{document}

\begin{equation}
(\source{a}+\source{4})(\target{b}+\target{3})=\mbox{\drawarrows}
\end{equation}

\end{document}

输出:

在此处输入图片描述

更新:标记每个箭头:

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}

\newcounter{source}
\newcommand\source[1]{%
    \tikz[remember picture,baseline,inner sep=0pt] {%
        \node [name=source-\thesource,anchor=base]{$#1$};
    }%
    \setcounter{target}{0}
    \stepcounter{source}
}

\newcounter{target}
\newcommand\target[1]{%
    \tikz[remember picture,baseline,inner xsep=0pt] {%
        \node [name=target-\thetarget,anchor=base]{$#1$};
    }%
    \setcounter{source}{0}
    \stepcounter{target}%
}
\newcommand\drawarrows{
    \tikz[remember picture, overlay, bend left=45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [red](source-0.north) to (target-\n.north) ;
              \node [red] at ([xshift=-5mm]target-\n.north) [above=2mm] {\i};
          }

    }
}

 \tikz[remember picture, overlay, bend left=-45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [blue](source-1.south) to (target-\n.south)  ;
      \pgfmathsetmacro{\ii}{\i+2)};
         \node [blue] at ([xshift=-2mm]target-\n.south) [below=2mm] {\pgfmathprintnumber \ii};
    }
}
}}



\begin{document}

\begin{equation}
(\source{a}+\source{4})(\target{b}+\target{3})=\mbox{\drawarrows}
\end{equation}

\end{document}

输出:

在此处输入图片描述

答案2

使用 PSTricks 只是一个更漂亮的解决方案。

\documentclass[preview,border=1cm,12pt,varwidth]{standalone}
\usepackage{pst-node,amsmath}
\psset{nodesep=2pt,linearc=2pt,arrows=->,linecolor=blue,arrowinset=0}
\def\lbl#1{\ncput*{\text{\tiny #1}}}
\begin{document}
\abovedisplayskip=0pt\relax% don't use this line in your production
\[
(\rnode{A}{a}+\rnode{B}{b})(\rnode{C}{c}+\rnode{D}{d})=\ldots
\ncbar[angle=90,offsetA=-1pt]{A}{C}\lbl{1}
\ncbar[angle=90,offsetA=1pt,arm=16pt]{A}{D}\lbl{2}
\ncbar[angle=-90,offsetA=1pt]{B}{C}\lbl{3}
\ncbar[angle=-90,offsetA=-1pt,arm=16pt]{B}{D}\lbl{4}
\]
\end{document}

在此处输入图片描述

答案3

另一个解决方案是,如果您在 MiKTeX 或(TeX Live、MacTeX)下使用开关启动它,则可以与pstricks编译。或者,您可以使用 进行编译:pdflatex--enable-write18-shell-escapeXeLaTeX

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}

\Large
\begin{postscript}
  \begin{align*}
    (\rnode{X1}{2x}+\rnode{Y1}{\smash[b]{3y}})(\rnode{X2}{4x}+\rnode{Y2}{5y}) & = (2x)(4x)+(2x)(5y)+(3y)(4x)+(3y)(5y) \\
                                                                              & = 8x²+10xy+12xy+15y² \\
                                                                              & = 8x²+22xy+15y²
  \end{align*}
  \psset{angle=90,nodesep=2pt, arrows=<->, arrowinset=0.2}
  \ncbar[arm=15pt]{Y1}{Y2}\ncbar[border=1.5pt]{X1}{X2}
  \psset{angle=-90,nodesep=4pt}
  \ncbar{X1}{Y2}\ncbar[arm=8pt]{Y1}{X2}
\end{postscript}

\end{document} 

在此处输入图片描述

相关内容