Working on a tool paper, I had the desire to share code alongside its output. With a combination of the `listings`, `caption`, and `color` packages, we can get a result that's nice looking.
The imports needed
```latex
\usepackage{color}
\usepackage{listings}
\usepackage{caption}
```
I want a think topbar that labels which column is the code section and which column is the output section.
```latex
\DeclareCaptionFormat{listing}
{\colorbox[cmyk]{0.73, 0.35, 0.15,.5}
{\parbox{\textwidth}{#1#2#3}}}
\DeclareCaptionFont{white}{\color{white}}
\captionsetup[lstlisting]{
format=listing,
labelfont=white,
textfont=white,
font={bf,footnotesize}
}
```
Next I define some colors that I would like to use as the theme for the code output:
```latex
\definecolor{keyblue}{rgb}{0.1, 0.1, 0.6}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{stringcol}{rgb}{0.58,0.4,0.1}
```
Setup for the code output
```latex
\lstset{
language=Python,
columns=flexible,
basicstyle={\small\ttfamily},
keywordstyle=\color{keyblue},
commentstyle=\color{dkgreen},
stringstyle=\color{stringcol},
breaklines=true,
breakatwhitespace=true,
tabsize=4
}
```
Then inside the document, you can use `minipage` to setup a two column layout.