3

Good morning,

I have found a lot questions and tutorials on how to align multi-line equations, even over several pages and such, but I am unable to figure out how to align several equations with paragraphs of text between them.

Here is a minimal working example of my problem:

    \documentclass[10pt,a4paper]{book}
    \usepackage[utf8]{inputenc}
    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usepackage{amssymb}
    \usepackage{fleqn}
    \begin{document}
    Since we have
    \begin{equation}
        e^x = \frac{d}{dx}e^x
    \end{equation}
    and
    \begin{equation}
        e^x = \int e^x dx
    \end{equation}
    one of my students concluded that
    \begin{equation}
        \int dx = \frac{d}{dx}.
    \end{equation}
    \end{document}

This compiles to:

Equation 1 and 2 are perfectly aligned, but 3 is not.

As you can see the first two equations are perfectly aligned since the left sides take up the same width. Equation 3 is not aligned as the left side is wider. I am looking for a simple solution to align all equal signs, at least on a page, if not the entire document.

In the full document that I am writing there are several lines of explanation between equations, sometimes with inline math, references and so on, therefore solutions that simple put a few words in plain text inside a math environment are not really viable in my opinion.

I hope that I have stated my question clearly and wish you a good day.

  • 3
    You might want to have a look at the macro \intertext. It's only supposed for one or two lines, so no fit for your problem, but it might be a good point to start looking for alternatives. – Dave Nov 29 '19 at 10:16
  • @Dave it works for longer text too. I've been working on an answer about it. – Disenchanted Lurker Nov 29 '19 at 10:18
  • 1
    I'm not sure why the equals sign should be aligned. The three equations are independent of each other, so they shouldn't be aligned. From a mathematical point of view, $e^x=\int e^x\,dx$ is almost as wrong as the student's claim. – egreg Nov 29 '19 at 10:46
  • See also tex.stackexchange.com/questions/409489/… – John Kormylo Nov 29 '19 at 15:42
4

I know you said that solutions that "put a few words in plain text inside a math environment" don't seem to be viable. But you might still want to consider the \intertext (amsmath) and \shortintertext (mathtools) commands.

These allow you to put whole paragraphs of text between the equations, including inline math and citations.

The difference between the two commands is in the spacing: \shortintertext has smaller space between paragraphs, as shown in the example below.

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{mathtools}

\usepackage{filecontents}

\begin{filecontents}{references.bib}
@inproceedings{TestSmith,
    title={This is a Test},
    author={Smith, John and Jones, Ben},
    booktitle={2016 Placeholder Conference on Citation Testing},
    pages={3--4},
    year={2016}
}
\end{filecontents}


\begin{document}

The "intertext" and "shortintertext" commands allow you to put text inside an align environment.
\begin{align}
c + c + e^x &= \frac{d}{dx}e^x 
\intertext{this is normal "intertext"} 
\intertext{It has large spacing between paragraphs} 
b + b + b + e^x &= \int e^x dx
\shortintertext{"shortintertext" from the "mathtools" package has smaller spacing}
\shortintertext{like this}
\int dx &= \frac{d}{dx}.
\shortintertext{This works even for multi-line paragraphs, inline math ($x=\alpha+\frac{a}{b+1}$) and citations~\cite{TestSmith}.}    
\shortintertext{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.}
\int dx &= \frac{d}{dx} + a + a + a.
\end{align}

\bibliographystyle{apalike}
\bibliography{references}

\end{document}

output of the code above

| improve this answer | |
  • Thanks for mentioning \shortintertext, I was looking for a possibility to decrease the vertical spacing as well. I think I will run with this method, it delivers exactly the output I was looking for. – terri Nov 29 '19 at 14:52
4

\intertext works for single or multiple pages if that's sufficient for your needs.

\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[fleqn]{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{fleqn}
\begin{document}

Since we have
\begin{align}
    e^x &= \frac{d}{dx}e^x
\intertext{and}
    e^x &= \int e^x dx
\intertext{one of my students concluded that.. one of my students concluded that.. one of my students concluded that..}
    \int dx &= \frac{d}{dx}.
\end{align}

\end{document}

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.