让 tikzpicture 环境切入方程

让 tikzpicture 环境切入方程

我是 tikz 包的新手,我怎样才能让箭头更靠近等号,并能让它自动对齐?

输出

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}

\begin{document}
$$\left(\int_{-\infty}^\infty e^{-x^2}\text{d}x\right)^2=\int_{-\infty}^\infty\int_{-\infty}^\infty e^{-x^2-y^2}\text{d}x\text{d}y$$

\hspace{3cm}
\begin{tikzpicture}
        \draw[<-](0.9,0.5) -- (0.9,0) -- (0,0) -- (0,-.5) node[anchor=north] {explanation};
\end{tikzpicture}
\end{document}

答案1

这可以\tikzmarknode通过tikzmarkTiZ 库。此命令创建 TiZ 节点基本上可以随意放置。在这里,等号是一个很好的选择,因为它能满足您的需要。可以tikzpicture使用remember pictureoverlay选项从访问节点。您需要编译两次,因为此技术依赖于文件.aux

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

% From egreg: https://tex.stackexchange.com/a/84308/73317
\newcommand{\diff}{\mathop{}\!\mathrm{d}}

\begin{document}
\[ \left( \int_{-\infty}^{+\infty} e^{-x^2} \diff x \right)^{\!2}
   \tikzmarknode{eqsign}{=}
   \int_{-\infty}^{+\infty} \!\!\!
     \int_{-\infty}^{+\infty} \! e^{-x^2-y^2} \diff x \diff y \]

\begin{tikzpicture}[remember picture, overlay]
  \draw[<-] (eqsign) ++ (0,-1ex) -- ++(0,-0.5) -- ++(-0.9,0) -- ++(0,-.5)
            node[anchor=north] {explanation};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

有关命令的解释,\tikznode请参阅 我对“如何在方程和矩阵中添加箭头?”的回答

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows} % for arrow tip stealth'xpdf 
\newcommand\tikznode[3][]{%
  \tikz[remember picture,baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
}
\usepackage{amsmath}

\begin{document}
\[\left(\int_{-\infty}^\infty e^{-x^2}\text{d}x\right)^2\mathrel{\tikznode{eq}{$=$}}\int_{-\infty}^\infty\int_{-\infty}^\infty e^{-x^2-y^2}\text{d}x\text{d}y
\]
\begin{tikzpicture}[remember picture,overlay]
  \draw[stealth'-,shorten <=2pt,rounded corners]
    (eq) |- ++(-0.9,-0.5) -- ++(0,-.5) node[below] {explanation};
\end{tikzpicture}
\end{document}

答案3

正如所提到的frougon 的回答tikzmark可以在这里使用。但是,我认为还应确保注释不与文本重叠。因此,可能需要将 放入tikzpicture方程式中,测量相关距离并将其添加。

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}

\newcommand{\diff}{\mathop{}\!\mathrm{d}}

\begin{document}
Some text before the equation.
\[ \left( \,\int\limits_{-\infty}^\infty \mathrm{e}^{-x^2} \diff x \right)^{2}
   \tikzmarknode{eqsign}{=}
   \int\limits_{-\infty}^\infty  \int\limits_{-\infty}^\infty 
   \mathrm{e}^{-x^2-y^2} \diff x \diff y 
\begin{tikzpicture}[remember picture,baseline={(tmp.base)}]
  \node(tmp){\vphantom{1}};
  \draw[latex-, overlay] (eqsign.south)  |- ++(-1,-0.7) -- ++ (0,-0.5)
            node[below] (expl) {explanation};
  % add point to tikzpicture to make it take the right size, subtract inner sep     
  \path ([yshift=2pt]expl.south-|tmp);
\end{tikzpicture}
\]
Some more text after the equation.
\end{document}

相关内容