2

I have a question, how to remove these white spaces between two subequations environments (marked with red '?'). I'm looking for the solution without any \vspace{} commands. I want to fix it automatically. enter image description here

Here is the MWE:

 \documentclass[preview,border={10pc 2pc 10pc 2pc}]{standalone}
 \usepackage{amsmath}

 \begin{document}

 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
 \begin{subequations}
 \begin{flalign}
  & f_1(x) = x^2 &\\
  & f_2(x) = x^2 &
 \end{flalign}
 \end{subequations}
 \begin{subequations}
 \begin{flalign}
  & g_1(x) = x^2 &\\
  & g_2(x) = x^2 &
 \end{flalign}
 \end{subequations}
 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

 \end{document}

3 Answers3

4

Here is a variant of subequations that allows for stepping the parent equation counter.

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}

\AtBeginDocument{\let\standardtheequation\theequation}
\newenvironment{subequations*}
 {%
  \subequations
  \counterwithin*{equation}{parentequation}%
  \let\theequation\standardtheequation
  \patchcmd{\theequation}{equation}{parentequation}{}{}%
  \apptocmd{\theequation}{\alph{equation}}{}{}%
  \newcommand{\substep}{\stepcounter{parentequation}}%
 }
 {\endsubequations}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{subequations*}
\begin{align}
  f_1(x) &= x^2 \\
  f_2(x) &= x^2 \\
\substep
  g_1(x) &= x^2 \\
  g_2(x) &= x^2
\end{align}
\end{subequations*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

\end{document}

enter image description here

With some twisting you can also refer to the global numbers. The label for the \substep number is input as an optional argument to \substep.

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}

\AtBeginDocument{\let\standardtheequation\theequation}
\makeatletter
\newenvironment{subequations*}
 {%
  \subequations
  \counterwithin*{equation}{parentequation}%
  \let\theequation\standardtheequation
  \patchcmd{\theequation}{equation}{parentequation}{}{}%
  \apptocmd{\theequation}{\alph{equation}}{}{}%
  \let\theparentequation\standartheequation
  \newcommand{\substep}[1][]{%
    \refstepcounter{parentequation}%
    \if\relax\detokenize{##1}\relax\else
      \ltx@label{##1}%
    \fi
  }%
 }
 {\endsubequations}
\makeatother

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{subequations*}\label{first}
\begin{align}
  f_1(x) &= x^2 \label{first-a} \\
  f_2(x) &= x^2 \label{first-b} \\
\substep[second]
  g_1(x) &= x^2 \label{second-a} \\
  g_2(x) &= x^2 \label{second-b}
\end{align}
\end{subequations*}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

\ref{first} \ref{first-a} \ref{first-b}

\ref{second} \ref{second-a} \ref{second-b}

\end{document}

enter image description here

egreg
  • 1,121,712
2

That looks wrong to me to have no vertical space because that are different equations. However:

\documentclass[preview,border={10pc 2pc 10pc 2pc}]{standalone}
\usepackage{amsmath}
\newcommand\IncCnt{\refstepcounter{parentequation}\setcounter{equation}{0}%
    \gdef\theparentequation{\arabic{parentequation}}}    
\begin{document}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut 
    labore et dolore magna aliqua.
    \begin{subequations}
        \begin{flalign}
        & f_1(x) = x^2 &\\
        & f_2(x) = x^2 &\\\IncCnt
        & g_1(x) = x^2 &\\
        & g_2(x) = x^2 &\label{foo}
        \end{flalign}
    \end{subequations}

foo

    \begin{align}
       f_1(x) &= x^2
    \end{align}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut 
    labore et dolore magna aliqua.~\ref{foo}

\end{document}

enter image description here

1

I wouldn't use multiple math environments but change the actual numbering inside of the environment. The following code solves your problem, but it does not work automatically yet. If you figure out how to increase the counter of the subequation environment, you might find an automatic solution.

\documentclass[preview,border={10pc 2pc 10pc 2pc}]{standalone}
\usepackage[fleqn]{amsmath}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor     incididunt ut labore et dolore magna aliqua.
\begin{subequations}
\begin{gather}
   f_1(x) = x^2 \\
   f_2(x) = x^2 \\
   g_1(x) = x^2 \tag{2a}\\ 
   g_2(x) = x^2 \tag{2b}
 \end{gather}
 \end{subequations}
 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

 \end{document}
Felix Phl
  • 285