lstnewenvironment 的浮动放置

lstnewenvironment 的浮动放置

我已经定义了这个环境:

\lstnewenvironment{pddl3}[1][]
{
    \lstset{
        keywordstyle=\color{black},
        commentstyle=\color{black},
        language= VBScript, 
        basicstyle=\small,
        numbers=left, numberstyle=\tiny,
        stepnumber=1, numbersep=5pt, frame=shadowbox, float=*, #1
    }
}{}

而且我找不到强制将文档中列出的内容保留在某些文本下的方法。例如,我尝试了这种方法,但没有任何改变:

\begin{pddl3}[caption=Esempio di azione STRIPS,float,floatplacement=H]\label{l_strips}]
(:action sposta
:parameters (?v ?f ?t)
:precondition (and (at ?v ?f) (diverso ?t ?f))
:effect (and (at ?v ?t) (not (at ?v ?f))
)
\end{pddl3}

答案1

float如果你根本不想让列表浮动,为什么要指定选项?你可以有一个caption选项和一个label选项(注意:不是 \label)甚至无需创建浮动对象。试试这个:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{color} % or xcolor
\usepackage{listings}
\addto\captionsitalian{%
    \def\lstlistingname{Codice}%
}

\lstnewenvironment{pddl3}[1][]
{
    \lstset{
        keywordstyle=\color{red}, % just to check that it works
        commentstyle=\color{black},
        language= VBScript, 
        basicstyle=\small,
        numbers=left, numberstyle=\tiny,
        stepnumber=1, numbersep=5pt, frame=shadowbox, #1
    }
}{}

\begin{document}

Testo che precede il listato.

\begin{pddl3}[caption={Esempio di azione STRIPS},label=l_strips]
(:action sposta
:parameters (?v ?f ?t)
:precondition (and (at ?v ?f) (diverso ?t ?f))
:effect (and (at ?v ?t) (not (at ?v ?f))
)
\end{pddl3}

Testo che segue il codice~\ref{l_strips}.

\end{document}

(根据您的需要调整代码,这只是一个例子。)您将获得以下内容:

Output of the code

相关内容