tikz
我正在尝试以最通用的方式 用来实现这种类似括号的结果。
天真地使用\overbracket{}
和\underbracket{}
来自mathtools
手动对齐黑客,例如
\[
\,\,\overbracket{\!\!\nabla A + \nabla A\!\!}\,\,
\]
缺点就是不能重叠。
到目前为止,我找到的最佳解决方案是使用tikz
如下所示的 MWE。 问题在于,tikzpictures
(似乎)需要overlay
选项才能使图片间坐标正常工作 — 然而,这也破坏了数学流程。(请注意下图中的对齐)。
这个例子可能会有帮助:化学方程式也类似。 非常感谢。
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{align*}
\mathcal{G} &= \nabla A + \nabla A
\\ \mathcal{G} &=
\begin{tikzpicture}[overlay, remember picture, baseline={(current bounding box.south)}]
\node[anchor=base, inner sep=0pt] (G1) at (0,0) {$\nabla$};
\end{tikzpicture}
A+{}\,
\begin{tikzpicture}[overlay, remember picture, baseline={(current bounding box.south)}]
\node[anchor=base, inner sep=0pt] (G2) at (0,0) {$\nabla$};
\draw[blue] (G2) -- +(0, .2) -- ($(G1) + (0, 0.2)$) -- (G1);
\end{tikzpicture}
A
\\ \mathcal{G} &= A + A
\end{align*}
\end{document}
答案1
您也可以使用该simplewick
包相当简单地完成此操作。
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{simplewick}
\begin{document}
\[
\acontraction[.5ex]{\nabla_\mu A_\nu \nabla^\mu A^\nu - \nabla_\mu A_\nu \nabla^\nu A^\mu = }{\nabla}{A}{\nabla}
\acontraction[.5ex]{\nabla_\mu A_\nu \nabla^\mu A^\nu - \nabla_\mu A_\nu \nabla^\nu A^\mu = \nabla A \nabla A -}{\nabla}{A\nabla}{A}
\bcontraction[.5ex]{\nabla_\mu A_\nu \nabla^\mu A^\nu - \nabla_\mu A_\nu \nabla^\nu A^\mu = \nabla}{A}{\nabla}{A}
\bcontraction[.5ex]{\nabla_\mu A_\nu \nabla^\mu A^\nu - \nabla_\mu A_\nu \nabla^\nu A^\mu = \nabla A \nabla A - \nabla}{A}{}{\nabla}
\nabla_\mu A_\nu \nabla^\mu A^\nu - \nabla_\mu A_\nu \nabla^\nu A^\mu = \nabla A \nabla A - \nabla A \nabla A
\]
\end{document}
答案2
您可以使用tikzmark
。通常这种方法的问题在于,要使用 来绘制内容overlay
,因此可能会经过等式的其他部分。这里计算了一些垂直填充并插入以避免这种情况。
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\newcommand{\Contract}[3][]{\begin{tikzpicture}[remember picture]
\tikzset{contract/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/contract/##1}}%
\begin{scope}[overlay]
\ifdim\pv{vsep}>0pt
\draw[style/.expanded=\pv{style}]
([yshift=\pv{gap}]#2.north) -- ++ (0,\pv{vsep}) -|
([yshift=\pv{gap}]#3.north);
\else
\draw[style/.expanded=\pv{style}]
([yshift=-\pv{gap}]#2.south) -- ++ (0,\pv{vsep}) -|
([yshift=-\pv{gap}]#3.south);
\fi
\end{scope}
\ifdim\pv{vsep}>0pt
\path let \p1=($(#2.north)-(#2.base)$),
\n1={\y1+\pv{gap}+\pv{vsep}-height("A")}
in node[baseline={(#2.base)}]{\vphantom{\raisebox{\n1}{.}}};
\else
\path let \p1=($(#2.base)-(#2.south)$),
\n1={\y1-\pv{gap}+\pv{vsep}+2pt}
in node[baseline={(#2.base)}]{\vphantom{\raisebox{\n1}{.}}};
\fi
\end{tikzpicture}%
}
\tikzset{contract/.cd,vsep/.initial=3pt,gap/.initial=1pt,style/.initial={-,thick}}
\begin{document}
\begin{align*}
\mathcal{G} &= \nabla A + \nabla A \\
\mathcal{G} &= \tikzmarknode{n1}{\nabla} A
+\tikzmarknode{n2}{\nabla} A \Contract{n1}{n2} \\
\mathcal{G} &= A + A
\end{align*}
\[
\nabla_\mu A_\nu \nabla^\mu A^\nu-
\nabla_\mu A_\nu \nabla^\nu A^\mu
=
\tikzmarknode{n3}{\nabla}\tikzmarknode{A3}{A}
\tikzmarknode{n4}{\nabla}\tikzmarknode{A4}{A}
+
\tikzmarknode{n5}{\nabla}\tikzmarknode{A5}{A}
\tikzmarknode{n6}{\nabla}\tikzmarknode{A6}{A}
\Contract{n3}{n4} \Contract[vsep=-3pt]{A3}{A4}
\Contract{n5}{A6} \Contract[vsep=-3pt]{n6}{A5}
\]
\[
\nabla_\mu A_\nu \nabla^\mu A^\nu-
\nabla_\mu A_\nu \nabla^\nu A^\mu
=
\tikzmarknode{m3}{\nabla}\tikzmarknode{B3}{A}
\tikzmarknode{m4}{\nabla}\tikzmarknode{B4}{A}
+
\tikzmarknode{m5}{\nabla}\tikzmarknode{B5}{A}
\tikzmarknode{m6}{\nabla}\tikzmarknode{B6}{A}
\Contract[style={blue,thick}]{m3}{m4} \Contract[vsep=-3pt,style={red,thick}]{B3}{B4}
\Contract[style={red,thick}]{m5}{B6} \Contract[vsep=-3pt,style={blue,thick}]{m6}{B5}
\]
\end{document}