Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I’d like to place a Nassi-Schneiderman diagram into my LaTeX document but also to have the source code for the shown algorithm beside it. Drawing the diagram worked just fine using the StrukTeXpackage, showing the source code isn’t a problem either.

The problem is: I can’t think of a way to have text (or in this case: the sourcecode) on the left and the diagram on the right (or vice versa). How do I solve this?

Here is the part of my code that is necessary for this question:

\documentclass{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[german,curves]{struktex}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{listings}
\usepackage{courier}
\lstset{
        basicstyle=\footnotesize\ttfamily, % Standardschrift
        numbers=left,               % Ort der Zeilennummern
        numberstyle=\tiny,          % Stil der Zeilennummern
        numbersep=5pt,              % Abstand der Nummern zum Text
        tabsize=3,                  %
        extendedchars=true,         %
        breaklines=true,            %
        keywordstyle=\color{RoyalBlue}\textbf,
        commentstyle=\color{ForestGreen},
        frame=bottomline,
         stringstyle=\color{WildStrawberry}\ttfamily, % Farbe der String
         xleftmargin=17pt,
         framexleftmargin=17pt,
         framexrightmargin=5pt,
         framexbottommargin=4pt,    
 }

\begin{document}
\begin{lstlisting}[language=Java]
int eingabe = 13;
    int vrbeingabe = eingabe;
    String ergebnis = "";

    while(vrbeingabe > 0) {
        if(vrbeingabe % 2 == 0) {
            ergebnis = ("0"+ergebnis);
            vrbeingabe = vrbeingabe / 2;
        } else {
            ergebnis = ("1"+ergebnis);
            vrbeingabe = vrbeingabe / 2;
        }
    }

    System.out.println("Die Dezimalzahl "+eingabe+" entspricht der Binaerzahl "+ergebnis);
\end{lstlisting}
\begin{struktogramm}(85,20)[Umwandlung dezimaler in binäre Zahlen]
    \assign[10]{Eingabe $i$}
    \assign[10]{bs $\gets \emptyset$}
    \while[8]{solang $i > 0$}
        \ifthenelse[15]{5}{6}
            {Rest bei $\frac{i}{2}$}{\sTrue}{\sFalse}
            \assign{bs $\gets$ "1" $+$ bs}
        \change
            \assign{bs $\gets$ "0" $+$ bs}
        \ifend
                   \assign{i $\gets \frac{i}{2}$}
               \whileend
    \assign[10]{Ausgabe bs}
\end{struktogramm}
\end{document}

So far, the output looks like this: output-of-code-above

With the minipage environment suggested in one of the answers, it looks like this: minipage

EDIT: Added the actual part of the code. Sorry for the inconvenience of my bad example.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

You can use two side-by-side minipages: (perhaps you'll need to adjust some settings):

\documentclass{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[german,curves]{struktex}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{listings}
\usepackage{courier}

\lstset{
        basicstyle=\footnotesize\ttfamily, % Standardschrift
        numbers=left,               % Ort der Zeilennummern
        numberstyle=\tiny,          % Stil der Zeilennummern
        numbersep=5pt,              % Abstand der Nummern zum Text
        tabsize=3,                  %
        extendedchars=true,         %
        breaklines=true,            %
        keywordstyle=\color{RoyalBlue}\textbf,
        commentstyle=\color{ForestGreen},
        frame=bottomline,
         stringstyle=\color{WildStrawberry}\ttfamily, % Farbe der String
         xleftmargin=17pt,
         framexleftmargin=17pt,
         framexrightmargin=5pt,
         framexbottommargin=4pt,    
 }

\begin{document}

%\begin{figure}% uncomment this, and the corresponding \end{figure} below 
%if you want to turn the object into a floating one; in this case, the 
%following \noindent is superfluous
\noindent\begin{minipage}[t]{0.5\textwidth}
\vspace*{0pt}
\begin{lstlisting}[language=Java,framexrightmargin=0pt]
int eingabe = 13;
    int vrbeingabe = eingabe;
    String ergebnis = "";

    while(vrbeingabe > 0) {
        if(vrbeingabe % 2 == 0) {
            ergebnis = ("0"+ergebnis);
            vrbeingabe = vrbeingabe / 2;
        } else {
            ergebnis = ("1"+ergebnis);
            vrbeingabe = vrbeingabe / 2;
        }
    }

    System.out.println("Die Dezimalzahl "+eingabe+" entspricht der Binaerzahl "+ergebnis);
\end{lstlisting}
\end{minipage}%
\begin{minipage}[t]{0.5\textwidth}
\vspace*{0pt}
\footnotesize
\begin{struktogramm}(60,20)[Umwandlung dezimaler in binäre Zahlen]
    \assign[10]{Eingabe $i$}
    \assign[10]{bs $\gets \emptyset$}
    \while[8]{solang $i > 0$}
        \ifthenelse[15]{5}{6}
            {Rest bei $\frac{i}{2}$}{\sTrue}{\sFalse}
            \assign{bs $\gets$ "1" $+$ bs}
        \change
            \assign{bs $\gets$ "0" $+$ bs}
        \ifend
                   \assign{i $\gets \frac{i}{2}$}
               \whileend
    \assign[10]{Ausgabe bs}
\end{struktogramm}
\end{minipage}
%\end{figure}

\end{document}

enter image description here

share|improve this answer
    
This does work but, as you said, there seem to be some settings I might have to adjust. Just as in your picture, the left minipage doesn’t start on par with the right one. As I haven’t set anything that would change the margin to the top, I’m wondering where this stems from. –  PattaFeuFeu Nov 3 '12 at 21:27
    
@PattaFeuFeu this is controlled by the optional argument of minipage; now I've updated my answer with the default vertical alignment. –  Gonzalo Medina Nov 3 '12 at 21:30
    
Having transferred the changes you made to my document, the code is now on top of the page, but the diagram isn’t anymore (I changed the code section to the actual code). It starts when the code is about halfway through. –  PattaFeuFeu Nov 3 '12 at 21:36
    
@PattaFeuFeu please add some code to your original question reproducing the problem mentioned; otherwise, all I can do is to guess, and that's not the right way to proceed. –  Gonzalo Medina Nov 3 '12 at 21:39
    
Sorry for the inconvenience; I changed it and also added a screenshot of the output with your code. –  PattaFeuFeu Nov 3 '12 at 21:50
show 3 more comments

Consider using wrapfig package:

\begin{wrapfigure}{r}{0.5\textwidth}
    \begin{struktogramm}(85,20)[Umwandlung dezimaler in binäre Zahlen]
        ...
    \end{struktogramm}
\end{wrapfigure}

That would place you diagramm on the right. And, obviously, text on the left.

It's possible to wrap into wrapfigure code:

\begin{wrapfigure}{r}{0.35\textwidth}
    \begin{lstlisting}[language=Java]
    // Java Code
    // to be on the left/right
    // of the Nassi-Shneiderman
    //diagramm
    \end{lstlisting}
\end{wrapfigure}

That would place the struktogramm on the left and code on the right.

share|improve this answer
    
Unfortunately, this doesn’t seem to work with \begin{struktogramm}…\end{struktogramm} –  PattaFeuFeu Nov 3 '12 at 20:29
    
The second attempt doesn’t work either. Here is a picture –  PattaFeuFeu Nov 3 '12 at 21:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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