新的

新的

梅威瑟:

\documentclass{article}

\usepackage{algorithm}
\usepackage{minted}

\newminted{python}{
}

\begin{document}

\begin{algorithm}
    \caption{Caption}
    \begin{pythoncode}
x = 12
y = 3

print(x / y)
    \end{pythoncode}
\end{algorithm}

\end{document}

结果:

姆韦

答案1

新的

\documentclass{article}
\usepackage{algorithm}
\usepackage{minted}
\BeforeBeginEnvironment{minted}{\begin{minipage}{\linewidth}}
\AfterEndEnvironment{minted}{\end{minipage}}
\newminted{python}{}
\begin{document}
\begin{algorithm}
\caption{Caption}
\begin{pythoncode}
x = 12
y = 3

print(x / y)
\end{pythoncode}
\end{algorithm}
\end{document}

在此处输入图片描述

老的

原因

您可以看到定义\kern2pt\hrule\relaxfloat.sty

\newcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
  \def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%
  \def\@fs@post{\kern2pt\hrule\relax}%
  \def\@fs@mid{\kern2pt\hrule\kern2pt}%
  \let\@fs@iftopcapt\iftrue}

解决方案

\documentclass{article}

\usepackage{algorithm}

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\fs@ruled}{\kern2pt\hrule\relax}{\kern-.5\baselineskip\hrule\relax}{}{}
\makeatother

\usepackage{minted}

\newminted{python}{
}

\begin{document}

\begin{algorithm}
    \caption{Caption}
    \begin{pythoncode}
x = 12
y = 3

print(x / y)
    \end{pythoncode}
\end{algorithm}

\end{document}

在此处输入图片描述

相关内容