删除双倍行距文档中单倍行距方程周围的多余空格

删除双倍行距文档中单倍行距方程周围的多余空格

我想在双倍行距文档中使用带有公式编号的单倍行距公式。我找到了解决此问题的方法:双倍行距文档中的单倍行距方程式,但这个解决方案在方程式周围添加了额外的空格。你能帮我修改补丁以让

\AtBeginDocument{%
 \abovedisplayskip=0pt plus 0pt minus 0pt
 \abovedisplayshortskip=0pt plus 0pt
 \belowdisplayskip=0pt plus 0pt minus 0pt
 \belowdisplayshortskip=0pt plus 0pt minus 0pt
}

工作?我的 MWE 如下:

\documentclass[a4paper]{article}

\usepackage{lipsum}
\usepackage{amsmath}
\usepackage[doublespacing,nodisplayskipstretch]{setspace}
\usepackage{etoolbox}

\makeatletter

\newcommand*\MySingleSpacePatch{%
    \begin{singlespace}%
    \vskip -\baselineskip
    \noindent
    \dimen@ \hsize
    \advance \dimen@ \p@
    \hskip \dimen@ \@minus \tw@\p@
    \null
}
\newcommand*\EndMySingleSpacePatch{%
    \end{singlespace}%
    \noindent\ignorespaces
}

\makeatother

\BeforeBeginEnvironment{equation}{\MySingleSpacePatch}
\AfterEndEnvironment{equation}{\EndMySingleSpacePatch}
\BeforeBeginEnvironment{gather}{\MySingleSpacePatch}
\AfterEndEnvironment{gather}{\EndMySingleSpacePatch}
\BeforeBeginEnvironment{align}{\MySingleSpacePatch}
\AfterEndEnvironment{align}{\EndMySingleSpacePatch}

\AtBeginDocument{%
 \abovedisplayskip=0pt plus 0pt minus 0pt
 \abovedisplayshortskip=0pt plus 0pt
 \belowdisplayskip=0pt plus 0pt minus 0pt
 \belowdisplayshortskip=0pt plus 0pt minus 0pt
}

\begin{document}

\lipsum*[2]
\begin{align}
    x&=y+1 \\
    a&=b
\end{align}
\lipsum*[4]

\lipsum*[2]
\begin{gather}
    x=y \\
    a=b
\end{gather}
\lipsum*[4]

\lipsum*[2]
\begin{equation}
  DEF = Abc
\end{equation}
\lipsum*[4]

\end{document}

答案1

使用

\makeatletter
\newcommand*\MySingleSpacePatch{%
    \begin{singlespace}%
        \vskip -2\baselineskip% changed <<<<<<<<<<<<<<<<<<<<<<<
        \noindent\dimen@ \hsize%
        \advance \dimen@ \p@%
        \hskip \dimen@ \@minus \tw@\p@%
        \null%
    }
    \newcommand*\EndMySingleSpacePatch{%
    \vskip -\baselineskip % added <<<<<<<<<<<<<<<<
    \end{singlespace}%
    \noindent\ignorespaces
}
\makeatother

是

\AtBeginDocument{... 是不需要的。

代码更简单,无需任何补丁或猜测

\documentclass[a4paper]{article}

\usepackage{lipsum}
\usepackage{amsmath}
\usepackage[doublespacing,nodisplayskipstretch]{setspace}

\begin{document}
    
    \setlength{\abovedisplayskip}{0pt}%
    \setlength{\belowdisplayskip}{0pt}%
    \setlength{\abovedisplayshortskip}{0pt}%
    \setlength{\belowdisplayshortskip}{0pt}%
    \setlength{\jot}{-5pt}% optional space between equations 
    
    \lipsum*[2]
    \begin{align}
        x&=y+1 \\
        a&=b
    \end{align}
    \lipsum*[4]
    
    \lipsum*[2]
    \begin{gather}
        x=y \\
        a=b
    \end{gather}
    \lipsum*[4]
    
    \lipsum*[2]
    \begin{equation}    
        DEF = Abc
    \end{equation}
    \lipsum*[4]
    
\end{document}

b

相关内容