答案1
我建议使用tikzmark
。命令是\tikzmarknode{<label>}{<content>}
。您可以在公式中使用多个带有不同标签的命令。然后使用remember picture, overlay
选项tikzpicture
选项并使用 Ti钾Z 命令来绘制各种注释。
代码中还使用了除之外的各种库tikzmark
:shapes.geometric
用于椭圆,shapes.arrows
用于“结果”箭头,fit
用于包含红色椭圆、蓝色矩形和黄色圆圈的内容,bending
用于改进蓝色箭头的箭头形状。
请记住,使用时,tikzmark
如果节点位置发生任何变化,都必须编译两次。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark, shapes.geometric, shapes.arrows, fit, bending}
\begin{document}
\[
\tikzmarknode{a1}{\frac{4}{2}}+\tikzmarknode{a2}{\frac{6}{3}}=
\frac{\tikzmarknode{b1}{(3\times 4)}+\tikzmarknode{b2}{(2\times 6)}}{\tikzmarknode{b3}{2\times 3}}=\tikzmarknode{c1}{\frac{12+12}{6}}=\tikzmarknode{c2}{\frac{24}{6}}=\tikzmarknode{d1}{4}
\]
\begin{tikzpicture}[remember picture, overlay, font=\sffamily]
\draw[red, thick, ->, shorten <=1em, , shorten >=1em](a2.south east)--node[below, pos=.45, scale=.4]{1}(a1.north west);
\node[draw=red, thick, ellipse, fit=(b1), inner ysep=0, inner xsep=-1mm](ell){};
\draw[thick, red] (ell)--++(0,.5)node[above, red, scale=.4]{This is important!};
\draw[red, thick] (b2.south west)--node[above=2mm, red, scale=.5]{\bfseries WRONG!}(b2.north east);
\draw[green!70!black, thick] (b3.east)--node[below]{$\uparrow$}node[below=5mm, align=left, green!70!black, scale=.5]{This multiplication is not\\necessary Try to simplify.}(b3.west) ([yshift=2pt]b3.east)--([yshift=2pt]b3.west);
\node[draw=blue, thick, fit=(c1), inner xsep=1pt](box){};
\draw[blue, thick, ->, shorten >=3pt] (box) to[out=90, in=90] (c2.north);
\node[draw=yellow!70!orange, thick, circle, fit=(d1), inner sep=1pt](cir){};
\node[draw=yellow!70!orange, thick, text=yellow!70!orange, single arrow, shape border rotate=180, anchor=west, scale=.4, single arrow tip angle=40, minimum height=30mm] at (cir.east){\quad RESULT};
\end{tikzpicture}
\end{document}
答案2
更简单(但不是和 )一样强大 的tikzmark
包就是这个annotate-equations
包。
这里有一个取自包文档的简短示例:
\documentclass{article}
\usepackage{mathtools}
\usepackage{annotate-equations}
\begin{document}
\renewcommand{\eqnhighlightheight}{\vphantom{\hat{H}}\mathstrut}
\begin{equation*}
i \tikzmarknode{hbar}{\mathstrut\hbar} \frac{\partial}{\partial t} \eqnmarkbox[blue]{Psi1}{\Psi(x, t)} = \eqnmark[red]{Hhat}{\hat{H}} \eqnmarkbox[blue]{Psi2}{\Psi(x, t)}
\end{equation*}
\annotate[yshift=3em]{above}{hbar}{$\hbar = \frac{h}{2\pi}$, reduced Planck constant}
\annotate[yshift=1em]{above}{Hhat}{Hamilton operator}
\annotatetwo[yshift=-1em]{below}{Psi1}{Psi2}{Wave function}
\end{document}