梅威瑟:
\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\relax
在float.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}