为了将我的列表置于我关注的页面上tex.se 上的教程.com 并产生以下代码:
{\renewcommand{\figurename}{Listing}
\begin{figure}[H] % the figure provides the caption
\centering % which should be centered
\caption{Example of factorial using the SAL actor language.}
\begin{tabular}{c}
\begin{lstlisting}[basicstyle= \footnotesize\ttfamily,
belowcaptionskip=0em,
language=SAL,
label={lst:salfactorial}]
def Factorial() [val, cust]
become Factorial() ||
if val = 0
then send [1] to cust
else let cont = new FactorialCont(val, cust)
in send [val - 1, cont] to self
end def
def FactorialCont(val, cust) [arg]
send [val * arg] to cust
end def
// Top level expression
let x = [recep] new Factorial()
in send [5] to x
\end{lstlisting}
\end{tabular}
\end{figure}}
这种方法的问题是我现在确实有一个列表(当我使用\autoref
它时显示Listing
)但它使用数字计数器。
因此,上面显示的图形/列表已编号Listing 2.1
,但上面的实际列表也打印为Listing 2.1
。
我不想用同一个计数器全部图表和列表,只需让这个图表使用列表计数器即可。因此,如果我有实际图表,它们将被编号为 1.1、1.2 和 1.3。如果我有两个实际列表和一个图表内的列表(如上所示),它们将被编号为列表 1.1、1.2 和 1.3。
最小示例
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\title{Test}
\author{Christophe De Troyer}
\date{May 2015}
\begin{document}
\section{Foo}
{\renewcommand{\figurename}{Listing}
\begin{figure}[H] % the figure provides the caption
\centering % which should be centered
\caption{Example of factorial using the SAL actor language.}
\begin{tabular}{c}
\begin{lstlisting}[basicstyle= \footnotesize\ttfamily,
belowcaptionskip=0em,
language=SAL,
label={lst:salfactorial}]
first listing
\end{lstlisting}
\end{tabular}
\end{figure}}
\begin{lstlisting}[basicstyle= \footnotesize\ttfamily,
belowcaptionskip=0em,
language=SAL,
caption={second listing},
label={lst:second}]
second listing
\end{lstlisting}
\end{document}