5

I wish to include Java-code formatted with lstlisting as a conclusion in a bussproofs proof tree. The code has to be in boxes so two peaces of code can be displayed next to each other in the same conclusion. I currently have the following, not working code. It works with plain text instead of listing but it looks bad. How do I put a listing for Java in there?

\documentclass[12pt, twoside]{scrreprt}
\usepackage{listings}
\usepackage{bussproofs}

\begin{document}

\begin{prooftree}
    \AxiomC{more proof}
    \UnaryInfC{
        \parbox{.5\textwidth}{
            \begin{lstlisting}[language=Java]
                //nicely formated code
             \end{lstlisting}
        }
        \parbox{.5\textwidth}{
            \begin{lstlisting}[language=Java]
                //more nicely formated code
            \end{lstlisting}
        }
    }
\end{prooftree}

\end{document}
Werner
  • 603,163
Zalktis
  • 53

1 Answers1

5

You can't have lstlisting in the argument to another command, in this case \UnaryInfC. The usual trick is to prepare the listing in a box and use the box in the argument:

\documentclass[12pt, twoside]{scrreprt}
\usepackage{listings}
\usepackage{bussproofs}

\newsavebox{\lstA}
\newsavebox{\lstB}

\begin{document}

\begin{prooftree}
\AxiomC{test}
\UnaryInfC{A}{B}
\end{prooftree}

\begin{prooftree}
\begin{lrbox}{\lstA}
\begin{minipage}{.45\textwidth}
\begin{lstlisting}[language=Java]
//nicely formatted code
\end{lstlisting}
\end{minipage}
\end{lrbox}
\begin{lrbox}{\lstB}
\begin{minipage}{.45\textwidth}
\begin{lstlisting}[language=Java]
//different formatted code
\end{lstlisting}
\end{minipage}
\end{lrbox}
    \AxiomC{more proof}
    \UnaryInfC{\usebox{\lstA}}{\usebox{\lstB}}
\end{prooftree}

\end{document}

enter image description here

egreg
  • 1,121,712