如果与单独的标题一起使用,列表编号错误

如果与单独的标题一起使用,列表编号错误

我在文档中使用 listings 包,为了在列表标题中使用脚注,我必须\caption\lstinputlisting

如果我现在创建文档,带有单独标题的列表似乎遵循与其他列表不同的编号 - 而周围的列表是“列表 5.6”和“列表 5.7”,带有单独标题的列表称为“列表 1”。

这是我正在使用的代码(我将其稍微简化了一下,但仍然与文档中的结构完全相同):

% This listing is working just fine (called Listing 5.6 in the document).
\begin{lstfloat}
    \lstinputlisting[label=code:abort,caption={Workin caption here},captionpos=b]{Inhalt/Code/abort.js}
\end{lstfloat}

Here is some text to talk about the listing...

% This listing is suddenly called Listing 1
\begin{lstfloat}
    \lstinputlisting[label=code:shell]{Inhalt/Code/shell.sh}
    \caption[Manipulation und Abfrage der Daten mithilfe von cURL]{Manipulation und Abfrage der Daten mithilfe von cURL\protect\footnotemark}
\end{lstfloat}

\footnotetext{\url{https://curl.haxx.se/}}

% This listing is working file as well (called Listing 5.7 in the document)
\begin{lstfloat}
    \lstinputlisting[label=code:connect,caption={Another working caption},captionpos=b]{Inhalt/Code/connect.js}
\end{lstfloat}

我不是 LaTeX 专家,也不知道哪里出了问题。

答案1

您应该阅读的文档listings

猜测lstfloathttps://tex.stackexchange.com/a/354023/4427

\begin{filecontents*}{\jobname.sh}
echo "Hello World"
\end{filecontents*}

\documentclass{article}

\usepackage{listings}
\usepackage{url}
\usepackage{float}

\newfloat{lstfloat}{htbp}{lop}
\floatname{lstfloat}{Listing}
\newcommand{\mylistoflistings}{\listof{lstfloat}{List of Listings}}
\AtBeginDocument{\counterwithin{lstlisting}{section}}

\begin{document}

\section{Test}

\begin{lstfloat}[!hp]
    \lstinputlisting[label=code:abort,caption={Workin caption here},captionpos=b]{\jobname.sh}
\end{lstfloat}

Here is some text to talk about the listing...

\begin{lstfloat}[!hp]
    \lstinputlisting[
      label=code:shell,
      captionpos=b,
      caption={%
       [Manipulation und Abfrage der Daten mithilfe von cURL]%
       {Manipulation und Abfrage der Daten mithilfe von cURL\protect\footnotemark}},
    ]{\jobname.sh}
\end{lstfloat}

\footnotetext{\url{https://curl.haxx.se/}}

Here is some text to talk about the listing...

\begin{lstfloat}[!hp]
    \lstinputlisting[label=code:connect,caption={Another working caption},captionpos=b]{\jobname.sh}
\end{lstfloat}

\end{document}

在此处输入图片描述

相关内容