3

Does anyone know of an elegant way to avoid having to manually put an \nonumber at the end of \shortintertext{} when it is at the last line? As illustrated by the parts of the minimal working example (MWE) below that is commented out by a %.

I am very happy to use \shortintertext{} from mathtools. \shortintertext{} do not produce a equation number, which I like, but if I use \shortintertext{} as the last thing in an {align} equation block \shortintertext{} produces an extra equation number (as this, see blow for MWE) \shortintertext{} too many equation numbers

It also seems as \shortintertext{} produces extra line spacing …

MWE (inspired by this SE example);

\documentclass[preview]{standalone}
\usepackage{mathtools}
\usepackage[usenames,dvipsnames]{xcolor}

\begin{document}
\begin{align}
\shortintertext{\color{gray}  We are trying to solve for $x$}
    3+x &=4\\
\shortintertext{\color{gray} Subtract 3 from both sides:} 
    x &=4-3 \
 \shortintertext{\color{gray} Hence, $x$ must be 1:}
    x &=1 
 \shortintertext{\color{gray} Some comments on the conclussion} % \nonumber
\end{align} %  \vspace{-3.4 em}
\end{document} 
2
  • 1
    The first and last \shortintertext should be normal text outside align. – egreg Apr 1 '17 at 9:13
  • @egreg, thank you for your feedback. I tried playing around with having my first and last comment outside align. However, there's a special line spacing for \shortintertext{} so that when I take comments outside align those comments do not have the same spacing as the rest of the equation comments. Maybe I shouldn't use \shortintertext{} at all. – Eric Fail Apr 1 '17 at 9:47
4

You can use a different approach:

\documentclass{article}
\usepackage{mathtools}
\usepackage[usenames,dvipsnames]{xcolor}

\newenvironment{compactequations}
 {\setlength{\abovedisplayskip}{2pt plus 2pt}%
  \setlength{\abovedisplayshortskip}{2pt plus 2pt}%
  \setlength{\belowdisplayskip}{2pt plus 2pt}%
  \setlength{\belowdisplayshortskip}{2pt plus 2pt}}
 {}

\begin{document}

\begin{compactequations}
\noindent\textcolor{gray}{We are trying to solve for $x$}
\begin{align}
    3+x &=4\\
\intertext{\color{gray} Subtract 3 from both sides:} % \nonumber
    x &=4-3 \\
 \intertext{\color{gray} Hence, $x$ must be 1:}
    x &=1
\end{align}
\textcolor{gray}{Some comments on the conclusion}
\end{compactequations}

\end{document}

enter image description here

Without aligning at the equals signs:

\documentclass{article}
\usepackage{mathtools}

\newenvironment{compactequations}
 {\setlength{\abovedisplayskip}{2pt plus 2pt}%
  \setlength{\abovedisplayshortskip}{2pt plus 2pt}%
  \setlength{\belowdisplayskip}{2pt plus 2pt}%
  \setlength{\belowdisplayshortskip}{2pt plus 2pt}}
 {}

\begin{document}

\begin{compactequations}
\noindent We are trying to solve for $x$
\begin{equation}
    3+x=4
\end{equation}
Subtract 3 from both sides:
\begin{equation}
    x=4-3
\end{equation}
Hence, $x$ must be 1:
\begin{equation}
    x=1 
\end{equation}
Some comments on the conclusion
\end{compactequations}

\end{document}

enter image description here

1
  • Thank you for taking the time to write up an elaborate answer. It does solve the issue, but it also adds quite a bit of code-customization to each align environment (and preamble). I've played around with having an ` \nonumber` after the last \shortintertext{}, inside my align environment, accompanied by an \vspace{-3.4 em} after the align environment, i.e. \end{align} \vspace{-3.4 em}. I've imagined a solution using a feature of mathtools I wasn't aware of or some other package that did the job with less customization. Your answer kinda give me a sense of the issue at hand. – Eric Fail Apr 1 '17 at 12:15

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.