Pergunta

Eu tenho uma macro que faz figuras lado a lado, abaixo. Ele usa Subfloats e, portanto, entra em uma figura.

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

Infelizmente, isso usa os contadores de figuras, não os listagens. Ele também aparece no índice errado e usa a palavra "figura" em vez de "listagens" na legenda, referências a ela, etc. Existe uma maneira de corrigir isso?

Eu preferiria uma maneira simples, como adicionar a palavra "listagem" em algum lugar ...

Foi útil?

Solução

Em vez de usar o flutuador embutido das lists, embrulhe-as em um flutuador personalizado:

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

Em seguida, use o mesmo flutuador (mylisting) para o uso do subfloat:

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

Isso precisa ser configurado no preâmbulo:

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

Outras dicas

Você pode querer dar uma olhada na documentação do subfloat. Tenho certeza de que há uma chamada de macro que faz com que o subfloat conte no ambiente da "figura". Você pode tentar redefinir o balcão do ambiente da "figura" para "listagens" - se isso fizer algum sentido.

Ok, esta é a resposta errada, mas eu fiz quase chegue lá assim. Ele não conseguiu adicionar legendas à direita \listof.

Quase lá. Provavelmente poderia ser feito melhor, mas isso quase funciona. Tudo o que resta é fazer com que a legenda apareça no arquivo .lol, não no arquivo .loc. Vou fazer uma pergunta sobre isso e, em seguida, conserte esta resposta.

Basicamente, isso acabou de fazer o balcão da "figura" e cópias sobre o contador "listagens". Após a figura, ele os coloca de volta.

% 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}
}
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top