获取方程式的顶部位置或对齐环境

获取方程式的顶部位置或对齐环境

我想要绘制一条从等式或对齐环境的顶部和底部开始的指导线(见下图):

这是我只在方程环境下进行的尝试:

\documentclass{article}
\usepackage{tikz, amsmath, bigints}
\usetikzlibrary{tikzmark}
\def\drawguideline#1{%
    \tikzmarknode{EquationPosition}{#1}%
    \begin{tikzpicture}[overlay, remember picture, black!20, every node/.style={left, font=\footnotesize}]
        \node at (EquationPosition.north) {0pt};
        \foreach \i in {10,20}{
            \draw[|-|] (EquationPosition.north) -- ++(0,\i pt) node {\i pt};
        }
        \node at (EquationPosition.south) {0pt};
        \foreach \i in {10,20}{
            \draw[|-|] (EquationPosition.south) -- ++(0,-\i pt) node {\i pt};
        }
    \end{tikzpicture}
    }
\begin{document}

\begin{equation*}
    \drawguideline{\bigint_0^1 f(x) dx = 1}
\end{equation*}

\end{document}

结果如下:

在此处输入图片描述

我怎样才能使它与如下的 algin 环境一起工作:

\begin{align*}
\drawguideline{
    1+1 &= 2\\
    2+2 &= 4}
\end{align*}

答案1

&\\用于在align环境内部创建类似表格的结构,而 tikz 对此表示不满。

以下是另一种方法:

\documentclass{article}
\usepackage{tikz, amsmath, bigints}
\usetikzlibrary{tikzmark}
\def\drawguideline#1{%
    \setlength{\abovedisplayskip}{0pt}
    \setlength{\belowdisplayskip}{0pt}
    \tikzmarknode{EquationPosition}{        
        \begin{minipage}[m]{\linewidth}#1\end{minipage}
    }%
    \begin{tikzpicture}[overlay, remember picture, black!20, every node/.style={left, font=\footnotesize}]
        \node at (EquationPosition.north) {0pt};
        \foreach \i in {10,20}{
            \draw[|-|] (EquationPosition.north) -- ++(0,\i pt) node {\i pt};
        }
        \node at (EquationPosition.south) {0pt};
        \foreach \i in {10,20}{
            \draw[|-|] (EquationPosition.south) -- ++(0,-\i pt) node {\i pt};
        }
    \end{tikzpicture}
}
\begin{document}
    
    \drawguideline{%
        \begin{align*}
                1+1 &= 2\\
                2+2 &= 4
        \end{align*}
    }
    
\end{document}

产生预期的结果:

输出

如果您想与普通段落一起使用而不会发生冲突:

\documentclass{article}
\usepackage{tikz, amsmath, bigints,lipsum}
\usetikzlibrary{tikzmark}
\def\drawguideline#1{%
    \setlength{\abovedisplayskip}{0pt}
    \setlength{\belowdisplayskip}{0pt}
    \vspace*{1cm}
    \tikzmarknode{EquationPosition}{        
        \begin{minipage}[m]{\linewidth}#1\end{minipage}
    }%
    \par\vspace*{1cm}
    \begin{tikzpicture}[overlay, remember picture, black!20, every node/.style={left, font=\footnotesize}]
        \node at (EquationPosition.north) {0pt};
        \foreach \i in {10,20}{
            \draw[|-|] (EquationPosition.north) -- ++(0,\i pt) node {\i pt};
        }
        \node at (EquationPosition.south) {0pt};
        \foreach \i in {10,20}{
            \draw[|-|] (EquationPosition.south) -- ++(0,-\i pt) node {\i pt};
        }
    \end{tikzpicture}
}
\begin{document}
    \lipsum[13]
    
    \drawguideline{%
    \begin{align*}
            1+1 &= 2\\
            2+2 &= 4
    \end{align*}}
    
    \lipsum[13]
    
    \drawguideline{%
    \begin{equation*}
        \bigint_0^1 f(x) dx = 1
    \end{equation*}%
    }
    
\end{document}

在最后一个例子中,我添加了额外的垂直空间和lipsum包,以便更好地集成到虚拟文本文档中。

相关内容