答案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}