3

I'd like to display both an image and a code using pdflatex, side-by-side to illustrate a concept. The code uses listing package.

How could I do that ?

2

If what you are looking for is to display an image with its corresponding source code, then the showexpl package might be what you are looking for.

But since I suspect you just want to use any picture next to some code, then I sugest using the minipage environment. For example:

\documentclass{article}
\usepackage{graphicx}
\usepackage{listings}

\begin{document}
\begin{minipage}{0.5\textwidth}
 \begin{lstlisting}
 Some code.
 \end{lstlisting}
\end{minipage}
\begin{minipage}{0.5\textwidth}
 \includegraphics{some_picture}
\end{minipage}
\end{document}

which yields the following output:

enter image description here

Of course, you can then adjust the parameters of the minipage as you see fit, but I find this basic structure to be sufficient.

Note that you can't put a float inside the minipage environment. For more information, see How to use figure inside a minipage?

Hope it helps!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.