Tikz Diagram 与图片节点对齐环境

Tikz Diagram 与图片节点对齐环境

我正在尝试重现图像。我可能可以自己做,但这可能不是最好的方法,所以我想问什么是最快和最简单的方法来实现结果:

\documentclass{article}

\usepackage{amsmath,tikz}
\newcommand{\der}[2]{\dfrac{d#1}{d#2}}

\begin{document}
\begin{center}
$\begin{aligned}[t]
     &\phantom{==}\der{}{x} (x^{2} \cdot x^{5}) \\ \\
             &=x^{2} \cdot \textcolor{red}{5x^{4}}+x^{5} \cdot 
 \textcolor{red}{2x}\\
             &=5x^{6}+2x^{6}\\
             &=7x^{6}
\end{aligned}$
\end{center}
\end{document}

输出:

在此处输入图片描述

我正在努力实现:

在此处输入图片描述

答案1

这是一项建议。它需要最新版本的 tikzmark,也就是说,如果您在过去 2 个月左右更新过 TeX 安装,它应该可以工作。

\documentclass{article}

\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark}
\newcommand{\der}[2]{\dfrac{\mathrm{d}#1}{\mathrm{d}#2}}

\begin{document}
\begin{center}
$\begin{aligned}[t]
     &\phantom{==}\der{}{x} (x^{2} \tikzmarknode{0}{\cdot} x^{5}) \\[0.8cm]
             &=\tikzmarknode{1}{x^{2}} \cdot 
             \tikzmarknode[red]{2}{5x^{4}}+
             \tikzmarknode{3}{x^{5}} \tikzmarknode{5}{\cdot}
\tikzmarknode[red]{4}{2x}\\
             &=5x^{6}+2x^{6}\\
             &=7x^{6}
\end{aligned}$
\end{center}
\begin{tikzpicture}[overlay,remember picture,cyan!70]
\path ([yshift=0.1cm]1.north) coordinate (aux);
\foreach \X in {1,...,4}
{\draw   (\X |-aux) node[above,circle,draw,font=\small,inner sep=1pt]
(L\X){\X};}
\draw[very thick] ([xshift=-2pt,yshift=2pt]L1.west) |- 
([xshift=2pt,yshift=8pt]L4.east) coordinate (aux2) -- ([xshift=2pt]L4.east);
\draw[very thick,-latex] (0.south) -- (0|-aux2);
\path ([yshift=-4pt]5.south) node[below,circle,draw,font=\small,inner
sep=1pt]{5};
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者(我很难判断5节点应该位于哪里)

\documentclass{article}

\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark,positioning}
\newcommand{\der}[2]{\dfrac{\mathrm{d}#1}{\mathrm{d}#2}}

\begin{document}
\begin{center}
$\begin{aligned}[t]
     &\phantom{==}\der{}{x} (x^{2} \tikzmarknode{0}{\cdot} x^{5}) \\[0.8cm]
             &=\tikzmarknode{1}{x^{2}} \cdot 
             \tikzmarknode[red]{2}{5x^{4}}+
             \tikzmarknode{3}{x^{5}} \cdot
\tikzmarknode[red]{4}{2x}\\
             &=5x^{6}+\tikzmarknode{5}{2x^{6}}\\
             &=7x^{6}
\end{aligned}$
\end{center}
\begin{tikzpicture}[overlay,remember picture,cyan!70]
\path ([yshift=0.1cm]1.north) coordinate (aux);
\foreach \X in {1,...,4}
{\draw   (\X |-aux) node[above,circle,draw,font=\small,inner sep=1pt]
(L\X){\X};}
\draw[very thick] ([xshift=-2pt,yshift=2pt]L1.west) |- 
([xshift=2pt,yshift=8pt]L4.east) coordinate (aux2) -- ([xshift=2pt]L4.east);
\draw[very thick,-latex] (0.south) -- (0|-aux2);
\node[right=3pt of 5,circle,draw,font=\small,inner sep=1pt]{5};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容