我想制作一个像下图这样的评论框,随着我写不同的示例,它会调整大小。我的 MWE 不多
\documentclass{article}
\usepackage{amsmath, mathtools,tikz}
\begin{document}
\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\ dx &=\int (\textcolor{red}
{x^{3}+1})^{10} \textcolor{blue}{3x^{2}\ dx} \\
&=\int \textcolor{red}{u}^{10}
\textcolor{blue}{du}
\end{align*}
\end{document}
输出:
我正在尝试用在橙色阴影区域周围绘制的黑框来重新创建。
答案1
使用tikzmark
,这并不那么困难:
\documentclass{article}
\usepackage{amsmath, mathtools,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\ dx &=\int (\textcolor{red} {x^{3}+1})^{10} \textcolor{blue}{3x^{2}\ dx} \tikzmark{eqt}\\
&=\int \textcolor{red}{u}^{10}\textcolor{blue}{du}
\end{align*}
\begin{tikzpicture}[overlay, remember picture]
\coordinate (x) at ($(pic cs:eqt)+(1,0)$);
\draw (x)--($(x)+(3,0)$);
\draw[red] (x) node[above right] {Substitution};
\draw ($(x)+(3,0)$) node[right,draw,fill=orange!50] {%
% Remove `draw' option if you don't want the box
$\begin{aligned}
u&=x^3+1,\\
du&=3x^2dx
\end{aligned}$};
\end{tikzpicture}
\end{document}
这个非常好且富有创意的解决方案是@土拨鼠:
\documentclass[fleqn]{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\,\mathrm{d}x
&\tikzmarknode{eq1}{=}\int (\textcolor{red} {x^{3}+1})^{10}
\textcolor{blue}{3x^{2}\, \mathrm{d}x} \\
&\tikzmarknode{eq2}{=}\int \textcolor{red}{u}^{10}\,\textcolor{blue}{\mathrm{d}u}
\end{align*}
\begin{tikzpicture}[overlay, remember picture]
\path (eq1) -- (eq2) coordinate[midway] (aux);
\draw[latex-] (eq2) -- (aux) -- ++ (5,0) node[above left] {substitute}
node[right,fill=orange!30] {%
$\begin{aligned}
u&=x^3+1\\
\mathrm{d}u&=3x^2\,\mathrm{d}x
\end{aligned}$};
\end{tikzpicture}
\end{document}
答案2
没有 tikz,我定义了一个可扩展的\xmathline
,以数学轴为中心,它接受在它上方和下方的书写,就像\xrightarrow
,并添加一个简单的\colorbox
:
\documentclass[svgnames]{article}
\usepackage{amsmath, mathtools,tikz}
\usepackage{xcolor}
\usepackage{bigstrut}
\newcommand{\xmathline}[2][]{%
\ext@arrow 0099\xmathlinefill@{#1}{#2}}%
\newcommand{\xmathlinefill@}{%
\arrowfill@{\relbar\bigstrut}\relbar\relbar}
\makeatother
\begin{document}
\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\ dx &=\int (\textcolor{red}
{x^{3}+1})^{10} \textcolor{blue}{3x^{2}\ dx}
\quad\xmathline{\text{\color{Crimson}substitution\quad}}\colorbox{NavajoWhite! 60}{$\begin{aligned} u & = x^3 + 1 \\ du & =3x^2\,dx \end{aligned} $} \\%
&=\int \textcolor{red}{u}^{10}
\textcolor{blue}{du}
\end{align*}
\end{document}