4

I'm using the amsmath align* environment to format multi line formulas. Unfortunately, the environment adds a lot of margin before and below the formula. I found only one solution to get rid of this margins, but I fear it is a little bit hacky:

\documentclass[12pt]{memoir}

\usepackage{amsmath}

\makeatletter
    \newenvironment{myalign*}{%
      \setlength{\abovedisplayskip}{-\baselineskip}%
      \setlength{\abovedisplayshortskip}{\abovedisplayskip}%
      \start@align\@ne\st@rredtrue\m@ne
    }%
    {\endalign}
    \makeatother

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi et
consequat erat, non malesuada tortor. Phasellus porta cursus risus, eu
rutrum ligula suscipit sed. Proin vestibulum malesuada lacinia.
\begin{myalign*}
x &= 4 \times 5 \\
y &= x
\end{myalign*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi et
consequat erat, non malesuada tortor. Phasellus porta cursus risus, eu
rutrum ligula suscipit sed. Proin vestibulum malesuada lacinia.

\end{document}

UPDATE: Also without the blank lines before and after the environment I get too much space. It works when I set both lengths to 0pt.

Is there also another way to avoid the margins?

  • 1
    Avoid blank lines around align*, that's all. – egreg Jun 17 '14 at 9:05
  • @egreg Nope :-) that's not all. I tested it for my MWE and without the blank lines I have the margin! – strauberry Jun 17 '14 at 9:09
  • The vertical space around the alignment is necessary for readability. – egreg Jun 17 '14 at 9:12
  • @egreg Agree when you use it in a plain text document. I use it in a different situation, so readability is fine for me ^^ – strauberry Jun 17 '14 at 9:13
  • Can you try and explain this different situation? – egreg Jun 17 '14 at 9:16
5

Is this what you want?

enter image description here

\documentclass{article}
\usepackage{amsmath,graphicx}
\newenvironment{smashedalign}
 {\par$\!\aligned}
 {\endaligned$\par}

\begin{document}
\begin{figure}[htp]
\centering
\includegraphics[height=2cm]{example-image-a.pdf}
\begin{smashedalign}
x &= 4 \times 5 \\
y &= x
\end{smashedalign}
\includegraphics[height=2cm]{example-image-b.pdf}
\end{figure}
\end{document}
|improve this answer|||||
8

No, don't set negative values for \abovedisplayskip that will cause the math to over-print the preceding paragraph.

The spurious white area is not vertical space added by align it is a blank horizontal line of a paragraph added by you by having a blank line before the display. This is not vertical space and is not dropped at the top of a page.

Never leave a blank line before display math environments.

If you delete the spurious blank lines in your input you get

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.