Graphics, Figures & Tableslistings — Let the Frame wrap tightly around the Code

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
steenreem
Posts: 6
Joined: Tue Apr 05, 2011 1:28 pm

listings — Let the Frame wrap tightly around the Code

Post by steenreem »

Hi,

I'm using lstlisting and subfig to place to code examples next to each other. However the frame of the listings, whether I use single frame or bottomline, always runs to the end of the line. So the left listing's frame goes through the right listing's frame.

I can use the 'linewidth' parameter of listings to set the width of frame. However this is prone to error. I have to tune the linewidth and space between the two listings, according to the listing's sizes.

I would rather have the listings package just wrap its frame around the listing, and use the frame as the outer bounding box of the listing, so that is doesn't collide with other listings.

Is that possible?
Thanks.

The current code I have is:

Code: Select all

\begin{figure}[H]
\centering
\begin{SubFloat}{\label{fig:beforeloopfusion}Before loop fusion}
\begin{lstlisting}[boxpos=b,frame=single,rulesep=1cm, framexrightmargin=0cm, xrightmargin=0cm]
...
\end{lstlisting}
\end{SubFloat}
%
\hspace{2cm}
%
\begin{SubFloat}{\label{fig:afterloopfusion}After loop fusion}
\begin{lstlisting}[boxpos=b,frame=single,linewidth = 4cm]
...     
\end{lstlisting}
\end{SubFloat}
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

listings — Let the Frame wrap tightly around the Code

Post by localghost »

With this poor information the problem is incomprehensible. Please submit a minimal example that is reduced to only relevant code and compilable as provided for anybody else.


Thorsten
Post Reply