Pregunta

Tengo una macro que hacer figuras de lado a lado, a continuación. Utiliza subfloats, y por lo que va en una 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}
}

Por desgracia, este utiliza los contadores de la figura, no los anuncios. También aparece en la mesa equivocada de contenidos, y utiliza la palabra "Figura" en lugar de "Listados" en el rubro, referencias a ella, etc. ¿Hay una manera de corregir esto?

Yo preferiría una manera simple, como la adición de la palabra "venta" en algún lugar ...

¿Fue útil?

Solución

En lugar de utilizar el incorporado en la flota de lstlistings, envolverlos en un flotador personalizado:

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

A continuación, utilizar el mismo flotador (mylisting) para el uso subfloat:

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

Esto necesita que todo se haya configurado en el 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}

Otros consejos

Es posible que desee echar un vistazo a la documentación subfloat. Estoy seguro de que hay una llamada a la macro que hace recuento subfloat en el medio ambiente "figura". Se podría tratar de redefinir el marco de "figura" en contra de "listados" -. Si eso tiene algún sentido en absoluto

OK, esta es la respuesta equivocada, pero lo hice casi llegan allí como este. Sólo se pudo agregar subtítulos a la \listof derecha.

Cerca de allí. Eso Probablemente se podría hacer mejor, pero esto casi funciona. Todo lo que queda es para que el subtítulo aparece en el archivo Lol, no el .loc. Voy a hacerle una pregunta al respecto, a continuación, fijar esta respuesta.

Básicamente, esto sólo respalda el contador de "figura", y copias en el mostrador "listados". Después de la figura, se los vuelve a.

% 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 bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top