GeneralCode Block and Graph side-by-side

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
dbrumley
Posts: 2
Joined: Thu Jul 24, 2008 11:20 pm

Code Block and Graph side-by-side

Post by dbrumley »

Hello,
I'm trying to figure out a nice way of putting a code block next to a graphic inside a figure. The reason I want to do this is the code block on the left is an example, and the graphic on the right would be a picture of the memory layout.

I've tried a couple of different things. For example, I tried subfigure, which didn't work. What I tried was (where lstlisting is part of listings.sty for typesetting code):
\begin{figure}
\subfigure[]{
\begin{lstlisting}
code
\end{lstlisting}
}
\subfigure[]{
\includegraphic{picture}
}
\end{figure}

I've also tried minipage, but there are some problems there. First, it requires manually specifying how much space each figure gets instead of figuring it out automatically. Second, there seems to be a large gap between figures. Also, I'm not sure what the total size is (it doesn't seem to be \linewidth, because making each figure .5\linewidth always causes the figures ot be stacked instead of side-by-side).

What I tried was:
\begin{figure}
\begin{minipage}[t]{.4\linewidth}
\begin{lstlisting}
code
\end{lstlisting}
\end{minipage}
\begin{minipage}[t]{.4\linewidth}
\includegraphics{picture}
\end{minipage}
\end{figure}


Is there a nice way to put code next to a graphic as part of one larger figure?

Thanks,
David

Recommended reading 2024:

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

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

Post Reply