3

I want to remake the \begin{align} environment \end{align} with some stylization and I have no idea how I can do this. Well, to be precise, I want two specific things to happen in this environment:

  1. I want each line break to add a vertical line where the command breaks, i.e.: enter image description here

  2. When it is an operation other than equality, I want it to look like this when there is a line break: enter image description here

I have no idea how to start developing code that does this... Maybe using tikz should be a simpler alternative, but I don't know how to implement this.

Both images that I posted I made the lines by hand drawing.

4
  • 1
    you could use tikzmark to record the position of the = then draw in the rules at the end Mar 3 at 21:35
  • 1
    Can you give as the math equation setup so that we don't have to type up or own align environment. And indeed, @DavidCarlisle's approach comes to mind immediately, though you will need to use a macro for the = or an active = to make it automated. Mar 3 at 21:36
  • Out of curiosity, why do you want these lines?
    – mickep
    Mar 3 at 22:44
  • During my undergraduate studies I had a class with a professor who used these lines to line up the equations on the blackboard and with that I acquired the habit of using them too, so I wanted to pass this on to LaTeX too, because I think it looks very nice and organized
    – Jimeens
    Mar 4 at 1:31

2 Answers 2

5

Here's a quick tikzmark version (though without the library because we don't need any advances techniques it has to offer).

Change the outer ysep to adjust the white space between the = and the actual line. (The inner ysep will contribute to the bounder box and might change the vertical placement of lines if it is too big.)

Code

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

Output

enter image description here

4
  • If it's just a plain line I'd be inclined to implement this in PGF to not carry around the overhead of TikZ (and tikzmark). — I wonder if it is possible to get the spacing between the current and the last line from amsmath (it does measure a lot on its own already after all) and to just \overset the = with a vertical rule. Mar 3 at 22:07
  • 1
    This warning mensage appears with this code: "Package pgf Warning: Returning node center instead of a point on node border. Did you specify a point identical to the center of node ``tma1''? on input line 25." How can I solve this??
    – Jimeens
    Mar 3 at 22:29
  • 2
    @Jimeens I've edited my answer to remove that warning my using \ifmeasuring@ that amsmath provides for when it only measures its environment's content, we can't draw anything then because those measurements aren't on the page which confuses PGF/TikZ. Mar 3 at 22:38
  • 1
    @Jimeens It should be noted that this only works when the whole align is on the same page. If it spread out over multiple pages this needs to be adjusted (the tikzmark library also saves the page number so we could check where the other = is) and you will need to specify how the connection should look then. Mar 3 at 22:54
4

As stated in the comments, you can place the equals signs in \tikzmarknodes (add {} for proper spacing) and then use tikz to draw lines between these nodes (which can span over several lines):

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

enter image description here

You must log in to answer this question.

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