结合 subfloat 和 newfloat 包用于子列表环境

结合 subfloat 和 newfloat 包用于子列表环境

我正在使用该subfloat包对相关图形进行分组;它们在图形列表中显示为 1a、1b 等。

现在,我想listing使用该包定义一个新的浮点数newfloat,它会生成自己的清单列表。

唉,我缺少类似sublistings环境的东西,这导致列表也被标记为 1a、1b 等:

\documentclass{article}
\usepackage[countmax]{subfloat}
\usepackage{newfloat}
\DeclareFloatingEnvironment{listing}

\begin{document}
\listoflistings

\begin{sublistings}
\begin{listing}
\caption{First listing}
\end{listing}
\begin{listing}
\caption{Second listing}
\end{listing}
\end{sublistings}

\end{document}

据我所知,该subfloat软件包仅支持subfiguressubtables

我无法复制并修改其代码来生成sublistings与 定义的浮点数一起工作的环境newfloat。有人能帮帮我吗?

答案1

这是货物崇拜编程,但它有效:获取可能相关的代码subfloat.sty,将其包含在\makeatletter/中,并用\makeatother替换 每个实例。figurelisting

\documentclass{article}
\usepackage[countmax]{subfloat}
\usepackage{newfloat}
\DeclareFloatingEnvironment{listing}

\makeatletter
\newcommand*\thesubfloatlisting{\themainlisting\alph{subfloatlisting}}
\newenvironment{sublistings}{%
  \sublistingsbegin
}{%
  \sublistingsend
  \global\@ignoretrue
}
\let\c@subfloatlisting=\c@listing
\newif\ifinsubfloatlistings
\newcommand{\sublistingsbegin}{%
\ifinsubfloatlistings
  \PackageError{subfloat}{Cannot start subfloatlistings inside
    a\MessageBreak subfloatlisting area}{You probably have used
    \string\sublistingsbegin\space or \string\begin{sublistings} inside
      the^^Jsame environment or after \string\sublistingsbegin.}%
\fi
\global\insubfloatlistingstrue
  \refstepcounter{listing}%
  \protected@xdef\listing@value{\the\c@listing}%
  \protected@xdef\themainlisting{\thelisting}%
  \global\let\thelisting@original=\thelisting
  \setcounter{listing}{0}%
  \gdef\thelisting{\thesubfloatlisting}%
  \ifsubfloat@countmax
    {\def\@setref##1##2##3{%
      \ifx##1\relax
        \protect\G@refundefinedtrue
        \setcounter{subfloatlistingmax}{0}%
        \PackageWarningNoLine{subfloat}{Reference `##3' on page
          \thepage \space undefined\MessageBreak
          (count subfloatlistings)}%
      \else
        \setcounter{subfloatlistingmax}{\expandafter\@firstoftwo##1}%
      \fi}%
    \ref{subfloat@@listing\listing@value}}%
  \fi
%%  \@ifpackageloaded{sublisting}{%
    \let\p@sublisting=\thesubfloatlisting
%%  }{}%
  \ignorespaces
}
\newcommand{\sublistingsend}{%
\ifinsubfloatlistings
\else
  \PackageError{subfloat}{Cannot stop subfloatlistings outside
    a\MessageBreak subfloatlisting area}{You probably have used
    \string\sublistingsend\space or \string\end{sublistings} without
      starting a^^Jsubfloatlisting area using the same environment or
      \string\sublistingsbegin.}%
\fi
\global\insubfloatlistingsfalse
  \ifsubfloat@countmax
    \subfloat@listinglabel{subfloat@@listing\listing@value}%
  \fi
  \setcounter{listing}{\listing@value}%
  \global\let\thelisting=\thelisting@original
%%  \@ifpackageloaded{sublisting}{%
    \let\p@sublisting=\thelisting
%%  }{}%
  \ignorespaces
}
%%
\ifsubfloat@countmax
  \newcounter{subfloatlistingmax}
\else
  \PackageWarningNoLine{subfloat}{Numbers of floats not
    counted:\MessageBreak
    If you use one of the counters subfloatlistingmax or\MessageBreak
    subfloattablemax you will get strange error messages\MessageBreak
    containing \string\c@subfloatlistingmax\space or\MessageBreak
    \string\c@subfloattablemax:\MessageBreak
    Please switch on countmax or
    remove the code using\MessageBreak
    the counter then.}
\fi
\ifsubfloat@countmax
  \newcommand*\subfloat@listinglabel[1]{\@bsphack
    \protected@write\@auxout{}%
           {\string\newlabel{#1}{{\the\c@listing}{\thepage}}}%
    \@esphack}
\fi
\makeatother

\begin{document}
\listoflistings

\begin{sublistings}
\begin{listing}
\caption{First listing}
\end{listing}
\begin{listing}
\caption{Second listing}
\end{listing}
\end{sublistings}

\end{document}

在此处输入图片描述

相关内容