Pau*_*gar 5 latex caption figure listings
我有一个宏观做并排数字,下面.它使用子浮点数,因此它在图中.
\newcommand{\listbylist}[6][showlines=true]{
\begin{figure}
\subfloat[ ]{
\lstinputlisting[showlines=true,#1]{#2}
\label{#4:A}
}
\hfill{}
\subfloat[ ]{
% by setting the frame to leftline, we avoid a box into oblivion
% turn off numbers
\lstinputlisting[showlines=true,frame=leftline,#1,numbers=none]{#3}
\label{#4:B}
}
\hfill{}
\caption[#5]{#6}
\label{#4}
\end{figure}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这使用了图计数器,而不是列表计数器.它也显示在错误的目录中,并在标题中使用"图"而不是"列表",引用它等等.有没有办法纠正这个问题?
我更喜欢一种简单的方法,比如在某处添加"清单"这个词......
不要使用 lstlistings 的内置浮点数,而是将它们包装在自定义浮点数中:
\begin{mylisting}
\begin{lstlisting}
int x = 1;
\end{lstlisting}
\end{mylisting}
Run Code Online (Sandbox Code Playgroud)
然后使用相同的浮点(mylisting)作为子浮点的用法:
\newcommand{\listbylist}[6][showlines=true]{
\begin{mylisting}
\subfloat[ ]{
...
}
\hfill{}
\subfloat[ ]{
...
}
\hfill{}
\caption[#5]{#6}
\label{#4}
\end{mylisting}
}
Run Code Online (Sandbox Code Playgroud)
这都需要在序言中设置:
\newfloat{mylisting}{tbphH}{lopbl}[chapter]
\floatname{mylisting}{Listing}
\newsubfloat{mylisting}
\newcommand{\listofmylistings}{\listof{mylisting}{List of Listings}}
% if you use the hyperref package
\providecommand*\theHmylisting{\themylisting}
Run Code Online (Sandbox Code Playgroud)