0

I want to draw a guide line (see the image below) that starts at the top and bottom of equation or align environments:

Here's my try that only works with equation environments:

\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}

and this is the result:

enter image description here

How can I make it work with algin environments like:

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

1 Answer 1

0

& and \\ are used to create a tabular like structure inside align environment, and tikz complains about them.

Here is an alternative way:

\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}

Yields the expected:

output

And if you want to use with normal paragraphs without collisions:

\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}

I added the extra vertical space and the lipsum package, in this last example to better integrate inside a dummy-text document.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .