列出的代码使用与第三个列表相关的一些文字上面的源代码猫文件2. 强制定位H解决了这个问题,但是这个选项在newfloat
包中不可用,因为有更多的字幕控制(TBH 目标是减少minted
和之间的间距caption
)。
有没有办法设置固定位置newfloat
?
我是 LATeX 的新手,所以也许应该使用不同的方法?
\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[
a4paper,
portrait,
margin=2cm,
]{geometry}
\usepackage{titletoc}
\usepackage{minted} % color source code files
\begin{document}
\chapter{chapter}
some text related to the first listing
\begin{listing}[!ht]
\caption[firstlisting]{firstlisting}
\begin{minted}[frame=single]{console}
cat file1
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
first listing
\end{minted}
\end{listing}
some text related to the second listing
\begin{listing}[!ht]
\caption[secondlisting]{secondlisting}
\begin{minted}[frame=single]{console}
cat file2
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
second listing
\end{minted}
\end{listing}
some text related to the third listing
\end{document}
答案1
如果您想使用H
浮动放置选项,请float
另外加载该包。据我所知,该包没有不兼容问题newfloat
。
\documentclass{article}
\usepackage{float,newfloat,lipsum}
\DeclareFloatingEnvironment{demo}
\begin{document}
\lipsum[1]
\begin{demo}[H]
\centering
Whatever\ldots
\caption{A useless demo}
\end{demo}
\lipsum[1]
\end{document}