我有做并排侧图中,下面的宏。它使用subfloats,如此这般中的图。

\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}
}

不幸的是,这里采用的图计数器,而不是信息的。它也显示在内容的错误表,并使用这个词在标题“图”,而不是“清单”,它引用等是否有办法来纠正这种?

我希望能有一个简单的方法,比如增加单词“上市”的地方...

有帮助吗?

解决方案

除了使用的内置浮子lstlistings的,在自定义浮动包裹它们:

\begin{mylisting}
\begin{lstlisting}
int x = 1;
\end{lstlisting}
\end{mylisting}

然后,使用用于subfloat使用相同的浮子(mylisting):

\newcommand{\listbylist}[6][showlines=true]{
  \begin{mylisting}
    \subfloat[ ]{
      ...
    }
    \hfill{}
    \subfloat[ ]{
      ...
    }
    \hfill{}
    \caption[#5]{#6}
    \label{#4}
  \end{mylisting}
}

这需要所有的前导码中设置:

\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}

其他提示

您可能想看看subfloat文档。我敢肯定有一个宏调用,使得subfloat计数的“人物”的环境。你可以尝试和计数器重新定义了“人物”环境“列表” - 如果让任何意义

OK,这是错误的答案,但我没有的几乎的那里是这样的。它不仅没有字幕添加到右边\listof

近那里。它 也许可以做得更好,但是这的几乎的工作。剩下要做的事情是让标题出现在.lol文件,而不是.loc档案。我会问一个关于这个问题,那么解决这个问题的答案。

基本上,这只是备份“人物”计数器,并复制过来的“列表”计数器。该图之后,它把它们放回。

% Need a counter to save the value to
\newcounter{pbsavefigurecounter}

\newcommand{\listbylist}[6][showlines=true]{
{% scope

   % Change ``Figure'' to ``Listing''
   \renewcommand{\figurename}{Listing}

   % save the figure counter
   \setcounter{pbsavefigurecounter}{\value{figure}}

   % copy the listings counter to the figure counter
   \setcounter{figure}{\value{lstlisting}}


   \begin{figure}
  \subfloat[ ]{
     \lstinputlisting[nolol,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[nolol,showlines=true,frame=leftline,#1,numbers=none]{#3}
     \label{#4:B}
  }
  \hfill{}

%  \float@caption{lol}[#5]{#6}
   \label{#4}
   \end{figure}

   % Update the listings counter
   \setcounter{lstlisting}{\value{figure}}

   % Restore the figure counter
   \setcounter{figure}{\value{pbsavefigurecounter}}

   % Change ``Listing'' back to ``Figure''
   \renewcommand{\figurename}{Figure}
}
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top