0

for the finetuning I have to show a codelisting and the result as an image next to each other, otherwise it will be displayed on the next page and i have to crop it extremely.

Here's my progress so far:

\begin{lstlisting}[captionpos=b,caption={Alle HTML Überschriften (Quellcode)},label=lst:headings]
<h1>Überschrift erster Ordnung</h1>
<h2>Überschrift zweiter Ordnung</h2>
<h3>Überschrift dritter Ordnung</h3>
<h4>Überschrift vierter Ordnung</h4>
<h5>Überschrift fünfter Ordnung</h5>
<h6>Überschrift sechster Ordnung</h6>
\end{lstlisting}

\begin{figure}[h]
\includegraphics[height = 100px]{headings1}
\caption{Alle HTML Überschriften (Ansicht) \label{headingsimage}}
\end{figure}

How can I put them next to each other?

Cfun
  • 1,840
  • @SAM This ought NOT to be closed as a duplicate unless the OP here is using memoir. The answer there uses \subbottom. How should the OP define that in order to use the answer with a different class? – cfr Jun 30 '16 at 00:52
  • 1
    We need a complete minimal working example, please. As you can see, posting mere fragments leaves your question ambiguous. – cfr Jun 30 '16 at 00:53

1 Answers1

1

i propose a solution using \minipage, the code may looks ugly if several lines are too long and will get wraped, so you must choose good parameters of both minipage width (consider the space between the two blocs; dont use 100% of the line width), image scaling scale and linewidth to obtain a nice shape. i hope i answreed your question.

\documentclass{report}
\usepackage{float}
\usepackage{listings}
\usepackage{graphicx}

\begin{document}
\begin{figure}[h]
\begin{minipage}{.5\textwidth}  %listing bloc will have 50% of the line width 
\lstset{linewidth = 4cm, breaklines=true} %set your listing lines widths, and set breaklines to true
\begin{lstlisting}
Your code here here..........
Your code here here..........
Your code here here..........
\end{lstlisting}
\end{minipage}
\qquad %space between listing bloc and the figure
\begin{minipage}{0.4\textwidth} %figure will have the remaning 40% of the line width
\includegraphics[scale=.4]{example-image}  %the image must be resized or scaled if needed
\caption{caption}
\end{minipage}
\end{figure}
\end{document}
Cfun
  • 1,840
  • Thanks, I have tried it with minipage, too but got compiling errors, I accidently closed the figure to early – pguetschow Jun 30 '16 at 06:35