格式化三项式因式分解

格式化三项式因式分解

我正在尝试以更复杂的方式编写此代码。我对这个输出很满意,但这是通过反复试验完成的。也许我可以使用 \tikzmark 来清理它?有什么建议吗?

 \documentclass{article}
 \usepackage{tikz,xcolor,amsmath,colortbl}

 \begin{document}
 For example, since
 $$(2x+1)(x+6)=2x^{2}+13x+6,$$ 
 a factored form of $2x^{2}+13x+6$ is $(2x+1)(x+6)$.\\
 Notice that $2x$ and $x$ are factors of $2x^{2}$, the first term of the 
 trinomial. Also, $6$ and $1$ are factors of $6$, the last term of the 
 trinomial, as shown:
\[ \begin{tikzpicture}
\node at (0,0) {$\color{blue}{2x^{2}}\color{black}{}+13x+\color{red} 
{6}\color{black}{}=(2x+1)(x+6)$};
%%%%%TOP Arrows
\draw[blue,-] (-2.3,.2)--(-2.3,.5)--(.7,.5);
\draw[blue,->] (1.5,.5)--(1.6,0.5)--(1.6,0.2);
\node at (1.1,.5) {\color{blue}{\small $2x \cdot x$}}; 
\draw[blue,->] (0.5,.5)--(0.5,.2);
%%%%%%BOTTOM Arrows
\draw[blue,-] (-.4,-.2)--(-.4,-.5)--(1.3,-.5);
\draw[blue,->] (2.1,-.5)--(2.2,-0.5)--(2.2,-0.2);
\node at (1.7,-.5) {\color{red}{\small $1 \cdot 6$}}; 
\draw[blue,->] (1.15,-.5)--(1.15,-.2);
\end{tikzpicture} \]

Also notice that $13x$, the middle term, is the sum of the following 
products:
\setlength{\arrayrulewidth}{.8pt}
\[ \begin{tikzpicture}
\node at (0,0) {$2x^{2}+13x+6=(\color{red}{2x}\color{black}{}+\color{blue} 
{1}\color{black}{})(\color{blue}{x}\color{black}{}+\color{red} 
     {6}\color{black}{})$};
     \node at (1.3,-1) {\begin{tabular}{rl}
     \cellcolor{cyan!25!white}&\cellcolor{cyan!25!white}\color{blue}{1x} \\
     \cellcolor{cyan!25!white}+&\cellcolor{cyan!25!white}\color{red}{12x} \\ 
   \hline
     \cellcolor{cyan!25!white}&\cellcolor{cyan!25!white}\color{black}{13x} 
   \\
   \end{tabular}};
   %%%%First Line(left to right)
   \draw[blue,-] (.5,-.2)--(1.3,-.9);
   %%%%Second line  
    \draw[blue,-] (1.2,-.2)--(1.3,-.5);
   %%%%Third line
    \draw[blue,-] (1.6,-.2)--(1.65,-.4);
    %%%%Fourth Line
    \draw[blue,-] (2.2,-.2)--(2,-.9);
    \node at (2.1,-1.45) [right] {\small $\color{blue}{\text{Middle 
   term}}$};    
    \end{tikzpicture} \]
  \end{document}

在此处输入图片描述

答案1

以下是基于tikzmark 的新版本,它还没有在 CTAN 上,所以你需要下载它。如你所见,我用它\tikzmarknode来制作方程节点的元素,然后使用覆盖 tikzpicture 来制作注释。唯一有点微妙的是,你不能用这种方式轻松地给背景着色。我最终明确地恢复了节点内容,想知道是否有一种可以自动化的方法。(我实际上非常肯定有,但现在没有时间解决这个问题。)

\documentclass{article}
\usepackage{tikz,xcolor,amsmath}
\usetikzlibrary{tikzmark,fit}

 \begin{document}
 For example, since
 \[(2x+1)(x+6)=2x^{2}+13x+6,\] 
 a factored form of $2x^{2}+13x+6$ is $(2x+1)(x+6)$.

 Notice that $2x$ and $x$ are factors of $2x^{2}$, the first term of the 
 trinomial. Also, $6$ and $1$ are factors of $6$, the last term of the 
 trinomial, as shown:\smallskip
\[ 
 \tikzmarknode{1}{\textcolor{blue}{2x^2}}+13x+
 \tikzmarknode{2}{\textcolor{red}{6}}=(2\tikzmarknode{3}{x}+\tikzmarknode{4}{1})
 (\tikzmarknode{5}{x}+\tikzmarknode{6}{6})
\]
\begin{tikzpicture}[overlay,remember picture]
\draw[blue,->] (1.north) -- ++(0,7pt) coordinate (aux1) -| (1.north -| 5) node[pos=0.49,anchor=east,fill=white,inner sep=0.5pt,font=\small]{$2x\cdot x$};
\draw[blue,->] (aux1 -|3) -- (1.north -|3);
\draw[blue,->] ([yshift=-1pt]2.south) -- ++(0,-8pt) coordinate (aux2) -| ([yshift=-1pt]6.south) node[pos=0.48,anchor=east,fill=white,text=red,inner sep=0.5pt,font=\small]{$1\cdot 6$};
\draw[blue,->] (aux2 -|4) -- ([yshift=-1pt]6.south -|4);
\end{tikzpicture}

Also notice that $13x$, the middle term, is the sum of the following 
products:
\begin{align*} 2x^2+13x+6=(\tikzmarknode{B1}{\textcolor{red}{2x}}+
\tikzmarknode{B2}{\textcolor{blue}{1}})&
(\tikzmarknode{B3}{\textcolor{blue}{x}}+
\tikzmarknode{B4}{\textcolor{red}{6}})\\
&\tikzmarknode{B5}{\textcolor{blue}{1x}}\\
\tikzmarknode{B6}{+}\quad&\tikzmarknode{B7}{\textcolor{red}{12x}}\\
&\tikzmarknode{B8}{13x}\quad\text{\textcolor{blue}{middle term}}
\end{align*}
\begin{tikzpicture}[overlay,remember picture]
\node[fill=cyan!20,fit=(B5)(B6)(B7)(B8)] (fit){};
\node[blue] at (B5) {$1x$}; 
\node at (B6) {$+$}; 
\node[red] at (B7) {$12x$};
\node[blue] at (B8) {$13x$};
\draw[thick] ([yshift=-3pt]B7.south -|fit.west) -- ([yshift=-3pt]B7.south -|fit.east);
\draw[blue] (B1) -- (B7) (B2) -- (B5.west) (B3) -- (B5.north) (B4) -- (B7);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容