在向公式添加标签是一种 tikz 方案,它在方程式的各个部分周围放置圆角框,以便可以标记它们。它看起来比普通的旧方案更美观\underbrace
,并且可以自动化,不会有太多麻烦。下面是一个使用 latex 命令执行此 tikz 操作的示例,无需担心细节:
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
% formula, text, node#
\newcommand{\mathWithDescription}[3]{%
\tikz[baseline]{%
\node[draw=red,rounded corners,anchor=base] (m#3)%
{$\displaystyle#1$};%
\node[above of=m#3] (l#3) {#2};%
\draw[-,red] (l#3) -- (m#3);%
}%
}
\newcounter{mathLableNode}
\newcommand{\mathLabelBox}[2]{%
\stepcounter{mathLableNode}%
\mathWithDescription{#1}{#2}{\themathLableNode}%
}
\begin{document}
\begin{equation}
\boldsymbol{\nabla}^2 =
\mathLabelBox{
\frac{\partial^2}{\partial r^2} + \frac{1}{r} \frac{\partial}{\partial r}{}
}{$\boldsymbol{\nabla}_{\mathrm{T}}^2$}
+ \frac{1}{r^2} \frac{\partial^2}{\partial \theta^2}
+ \frac{\partial^2}{\partial z^2}
\end{equation}
\begin{equation}
\mathbf{E} =
\mathLabelBox{
\mathbf{E}_0
}{A vector, with a chosen polarity}
\mathLabelBox{
u(r, \theta, z)
}{
Slowly varying (complex) envelope
}
e^{i k_0 z}.
\end{equation}
\end{document}
我可以将其\mathLabelBox{}{}
作为 \underbrace{}_{} 的一对一替代品。以下是示例 latex 产生的结果:
我认为对于短公式(公式(1))来说它看起来相当不错,但对于包含长文本的短公式(公式(2))来说则不然。
看起来更好的方法是将文本放在一边,然后绘制指向元素的箭头。我发现使用 tikz 也可以做到这一点,从光束箭可以生成类似下面的页面
这是使用以下 MWE 生成的
% from http://www.texample.net/tikz/examples/beamer-arrows/ (switching to article class)
\documentclass{article} %
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{arrows,shapes}
\begin{document}
\tikzstyle{every picture}+=[remember picture]
\begin{itemize}%[<+-| alert@+>]
\item Coriolis acceleration
\tikz \node[coordinate] (n1) {};
\end{itemize}
\begin{equation*}
\vec{a}_p = \vec{a}_o+\frac{d^2}{dt^2}\vec{r} +
\tikz[baseline]{
\node[fill=blue!20,anchor=base] (t1)
{$ 2\vec{\omega}_{ib}\times\frac{d}{dt}\vec{r}$};
} +
\tikz[baseline]{
\node[fill=red!20, ellipse,anchor=base] (t2)
{$\vec{\alpha}_{ib}\times\vec{r}$};
} +
\tikz[baseline]{
\node[fill=green!20,anchor=base] (t3)
{$\vec{\omega}_{ib}\times(\vec{\omega}_{ib}\times\vec{r})$};
}
\end{equation*}
\begin{itemize}
\item Transversal acceleration
\tikz\node [coordinate] (n2) {};
\item Centripetal acceleration
\tikz\node [coordinate] (n3) {};
\end{itemize}
\begin{tikzpicture}[overlay]
\path[->] (n1) edge [bend left] (t1);
\path[->] (n2) edge [bend right] (t2);
% \path[->] (n3) edge [out=0, in=-90] (t3);
\path[->] (n3) edge [bend right] (t3);
\end{tikzpicture}
\end{document}
但看起来并不像我上面使用的更简单的 tikz 那样容易实现自动化。(编辑注:在添加上面的 MWE 时,它看起来并不像我最初想象的那么糟糕……很多复杂性实际上是由于 beamer 特定的东西)。
我想要一个\underbrace
类似我的命令\mathLabelBox
,将 beamer 示例中的样条箭头合并在一起?有没有比上面 beamer 箭头页面示例中的多部分代码更简单的方法?
答案1
代码
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\newif\ifclipme\clipmetrue
\tikzset{labelstyle/.style={LabelStyle/.append style={#1}},linestyle/.style={LineStyle/.append style={#1}}}
\tikzset{LabelStyle/.initial={},LineStyle/.initial={}}
\newcommand{\mathWithDescription}[4][]{{%
\tikzset{#1}%
\tikz[baseline]{
\node[draw=red,rounded corners,anchor=base] (m#4) {$\displaystyle#2$};
\ifclipme\begin{pgfinterruptboundingbox}\fi
\node[above of=m#4,font=\strut, LabelStyle] (l#4) {#3};
\draw[-,red, LineStyle] (l#4) to (m#4);
\ifclipme\end{pgfinterruptboundingbox}\fi
}%
}}
\newcommand{\mathWithDescriptionStarred}[3][]{{%
\clipmefalse%
\mathWithDescription[#1]{#2}{#3}{\themathLableNode}%
}}
\newcounter{mathLableNode}
\newcommand{\mathLabelBox}[3][]{%
\stepcounter{mathLableNode}%
\mathWithDescription[#1]{#2}{#3}{\themathLableNode}%
\vphantom{\mathWithDescriptionStarred[#1]{#2}{#3}{\themathLableNode}}%
}
\begin{document}
\begin{equation}
\boldsymbol{\nabla}^2 = \mathLabelBox{\frac{\partial^2}{\partial r^2} + \frac{1}{r} \frac{\partial}{\partial r}}
{$\boldsymbol{\nabla}_{\mathrm{T}}^2$}
+ \frac{1}{r^2} \frac{\partial^2}{\partial \theta^2} + \frac{\partial^2}{\partial z^2}
\end{equation}
\begin{equation}
\mathbf{E} =
\mathLabelBox[
labelstyle={yshift=1.2em},
linestyle={}
]{\mathbf{E}_0}{A vector, with a chosen polarity} \cdot
\mathLabelBox[
labelstyle={xshift=2cm},
linestyle={out=270,in=90, latex-}
]{u(r, \theta, z)}{Slowly varying (complex) envelope} \cdot e^{i k_0 z}.
\end{equation}
\end{document}
输出
一个简单的例子
代码
\begin{equation}
\mathbf{E} = \mathLabelBox{\mathbf{E}_0}{A vector, with a chosen polarity} \cdot
\mathLabelBox[labelstyle={below of=m\themathLableNode,below of=m\themathLableNode}]{u(r, \theta, z)}{Slowly varying (complex) envelope} \cdot e^{i k_0 z}.
\end{equation}