Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Avoid blank lines around align*, that's all. –  egreg Jun 17 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 at 9:09
    
The vertical space around the alignment is necessary for readability. –  egreg Jun 17 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 at 9:13
    
Can you try and explain this different situation? –  egreg Jun 17 at 9:16
show 4 more comments

2 Answers 2

up vote 5 down vote accepted

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}
share|improve this answer
    
Ab-so-lu-te-ly :-) Thank you! –  strauberry Jun 17 at 9:32
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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