Látex Dos entornos letreros subtitulados uno al lado del otro
Pregunta
¿Cómo obtener dos entornos literales dentro de flotadores con subtítulos automáticos uno al lado del otro?
\usepackage{float,fancyvrb}
...
\DefineVerbatimEnvironment{filecontents}{Verbatim}%
{fontsize=\small,
fontfamily=tt,
gobble=4,
frame=single,
framesep=5mm,
baselinestretch=0.8,
labelposition=topline,
samepage=true}
\newfloat{fileformat}{thp}{lof}[chapter]
\floatname{fileformat}{File Format}
\begin{fileformat}
\begin{filecontents}
A B C
\end{filecontents}
\caption{example.abc}
\end{fileformat}
\begin{fileformat}
\begin{filecontents}
C B A
\end{filecontents}
\caption{example.cba}
\end{fileformat}
Entonces, básicamente, solo necesito que esos ejemplos sean uno al lado del otro (y mantengan la niñera automática de los subtítulos). He estado intentando por un tiempo ahora.
Solución
Encontré la soulución finalmente.
\usepackage{caption}
\begin{fileformat}[h]
\centering
\begin{minipage}[b]{0.4\textwidth}
\begin{filecontents}
A B C
\end{filecontents}
\captionof{fileformat}{example.abc}
\end{minipage}
\quad
\begin{minipage}[b]{0.4\textwidth}
\begin{filecontents}
C B A
\end{filecontents}
\captionof{fileformat}{example.cba}
\end{minipage}
\end{fileformat}
La solución del problema es hacer una leyenda independientemente del entorno utilizando caption
paquete macro \captionof{fileformat}{Our Caption}
.
Otros consejos
Use minipage como en este ejemplo, que coloca dos imágenes de lado dentro de una figura flotante con subtítulos separados
\begin{figure}[htbp]
\centering
\begin{minipage}[b]{5 cm}
\includegraphics{filename 1}
\caption{caption 1}
\label{labelname 1}
\end{minipage}
\begin{minipage}[b]{5 cm}
\includegraphics{filename 2}
\caption{caption 2}
\label{labelname 2}
\end{minipage}
\end{figure}
Para subtítulos verbatim
entornos que puede usar listings
(que ofrecerá mucho más que un subtítulo simple, resaltado de sintaxis y numeración de línea también de forma gratuita) o definirá el suyo propio float
entorno utilizando el paquete con el mismo nombre.
Un ejemplo (de Wikibooks):
\documentclass{article}
\usepackage{float}
\floatstyle{ruled}
\newfloat{program}{thp}{lop}
\floatname{program}{Program}
\begin{document}
\begin{program}
\begin{verbatim}
class HelloWorldApp {
public static void main(String[] args) {
//Display the string
System.out.println("Hello World!");
}
}
\end{verbatim}
\caption{The Hello World! program in Java.}
\end{program}
\end{document}