答案1
这是一个快速tikzmark
版本(虽然没有库,因为我们不需要它提供的任何先进技术)。
更改以调整和实际线条outer ysep
之间的空白。(会影响边界框,如果 太大,可能会改变线条的垂直位置。)=
inner ysep
代码
\documentclass[varwidth]{standalone}
%\documentclass{article}
\usepackage{amsmath, tikz}
\newcommand*\eqlineset{\pgfqkeys{/eqlines}}
\eqlineset{
picture/.style={baseline, remember picture},
line/.style={thick, draw=orange, line cap=round},
node/.style={
minimum size=+0pt, inner sep=+0pt, outer ysep=+.3333em, anchor=base,
name=tma\thetikzmarkalign},
}
\newcounter{tikzmarkalign}
\makeatletter
\AtBeginEnvironment{align}{%
\setcounter{tikzmarkalign}{0}%
\newcommand*\noeq{\hphantom{{}={}}}%
\newcommand*\eq{
\ifnum\value{tikzmarkalign}=0
\mathrel{\tikz[/eqlines/picture]\node[/eqlines/node]{$=$};}
\else
\mathrel{
\begin{tikzpicture}[/eqlines/picture]
\node[/eqlines/node] (tma\thetikzmarkalign) {$=$};
\unless\ifmeasuring@
\path[/eqlines/line, overlay] (tma\thetikzmarkalign)
-- (tma\pgfinteval{\thetikzmarkalign-1});
\fi
\end{tikzpicture}
}
\fi
\stepcounter{tikzmarkalign}
}%
}
\makeatother
\begin{document}
\begin{align}
Lorem & \eq Ipsum \\
& \eq dolor sit amet,\\
& \noeq + \frac{consetetur sadipscing elitr}{sed diam nonumy} \\
& \eq eirmod tempor invidunt.
\end{align}
\end{document}
输出
答案2
正如评论中所述,您可以放置等号\tikzmarknodes
(添加{}
适当的间距),然后使用tikz
在这些节点之间画线(可以跨越多条线):
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{align}
x & \tikzmarknode{eq1}{{}={}} a^2 + 2ab + b^2 \\
& \tikzmarknode{eq2}{{}={}} (a + b)^2
\end{align}
\begin{tikzpicture}[remember picture, overlay]
\draw[very thick, orange, shorten >=2pt, shorten <=2pt] (eq1) -- (eq2);
\end{tikzpicture}
\end{document}