如何消除两个“子方程式”环境之间的空白?

如何消除两个“子方程式”环境之间的空白?

我有一个问题,如何删除两个subequations环境之间的这些空格(用红色“?”标记)。我正在寻找不使用任何\vspace{}命令的解决方案。我想自动修复它。 在此处输入图片描述

以下是 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}

答案1

这是一个subequations允许步进父方程计数器的变体。

\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}

在此处输入图片描述

经过一些调整,您还可以引用全局数字。数字的标签\substep作为 的可选参数输入\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}

在此处输入图片描述

答案2

我觉得这是不对的垂直空间,因为那是不同的方程。然而:

\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}

在此处输入图片描述

答案3

我不会使用多个数学环境,而是更改环境内部的实际编号。以下代码解决了您的问题,但它还不能自动运行。如果您弄清楚如何增加子方程环境的计数器,您可能会找到一个自动解决方案。

\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}

相关内容