算法和 hyperref 包:奇怪的交互

算法和 hyperref 包:奇怪的交互

我不确定下面的错误是否已被报告,因为我无法在网上找到明确的信息。请参阅 MWE:如果没有注释,则方程式下方的空间相当大,比注释包时的空间大得多。看起来这是与包命令\usepackage{hyperref}之间的不良交互:hyperrefSTATEalgorithmic

\documentclass{book}
\usepackage{algorithmic}
\usepackage{hyperref}
\begin{document}
\setlength\abovedisplayshortskip{0pt}
\setlength\belowdisplayshortskip{0pt}
\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}
\begin{algorithmic}
\STATE text text text text text text text text text text text text text
\begin{equation}
\cos\pi=-1
\end{equation}
\STATE text text text text text text text text text text text text text
\STATE text text text text text text text text text text text text text
\begin{equation}
\cos\pi=-1
\end{equation}
text text text text text text text text text text text text text
\end{algorithmic}
text text text text text text text text text text text text text
\begin{equation}
\cos\pi=-1
\end{equation}
text text text text text text text text text text text text text
\end{document}

在此处输入图片描述

答案1

改变

\usepackage{algorithmic} 

\usepackage{algorithmicx} 

或者

\usepackage{algpseudocode}

并且\STATE不会\State 产生空白空间

最小示例:

\documentclass{book}
\usepackage{algorithmicx} 
%\usepackage{algpseudocode}
\usepackage{hyperref}

\begin{document}
\setlength\abovedisplayshortskip{0pt}
\setlength\belowdisplayshortskip{0pt}
\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}
\begin{algorithmic}
\State text text text text text text text text text text text text text
\begin{equation}
\cos\pi=-1
\end{equation}
\State text text text text text text text text text text text text text
\State text text text text text text text text text text text text text
\begin{equation}
\cos\pi=-1
\end{equation}
text text text text text text text text text text text text text
\end{algorithmic}
text text text text text text text text text text text text text
\begin{equation}
\cos\pi=-1
\end{equation}
text text text text text text text text text text text text text
\end{document}

输出: 在此处输入图片描述

相关内容