# How to achieve this two column style?

I’d like to add some code examples in two column form. The left is a description and the right is the REPL input code and output.

Here’s an example of what I’d like to achieve:

Are there well known packages for this type of environment?

Update:

Here's what I've tried so far, but it's rather messy:

Here's a MWE:

\documentclass{book}
\usepackage{a4wide}
\usepackage{tabularx}
\usepackage[]{sourcecodepro}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}

\newlength\textlen
\newlength\codelen
\newlength\halflen
\setlength\halflen{\dimexpr.5\columnwidth-2\tabcolsep-0.5\arrayrulewidth\relax}
\setlength\textlen{.95\halflen}
\setlength\codelen{1.05\halflen}

\usepackage{color}
\definecolor{mygray}{rgb}{0.9,0.9,0.9}

\usepackage{minted}
\setminted{
baselinestretch=1,
tabsize=4,
fontsize=\fontsize{8}{11}
}

\begin{document}
\fontsize{12}{14}\selectfont

\justify
We restrict our sorting functions to permutations of the numbers $1\cdots n$. A simple way to visualize the amount of sortedness'' in such a list of numbers is a picture obtained with {\fontsize{10}{12}\selectfont\texttt{ListPlot}}.
\vspace{1.5mm}

{
\fontfamily{ptm}\selectfont
\fontsize{9}{11}\selectfont
\def\arraystretch{2}
\noindent\begin{tabular}{@{}p{\textlen}p{\codelen}@{}}
This definition is used to plot permutations of the numbers $1\cdots n$ with suitable settings of graphics options. &
\begin{minipage}[t]{0.5\textwidth}
\begin{minted}{Mathematica}
In[1]:= PermutationPlot[l_List, opts___] :=
ListPlot[ l,
PlotRange -> { {0.5, Length[l]+0.5},
{0.5, Length[l]+0.5} },
PlotStyle -> PointSize[0.75/Length[l]],
opts, Axes->None, FrameTicks->None,
Frame->True, AspectRatio->1 ]
\end{minted}
\end{minipage}\\
Here is a random permutation. &
\begin{minipage}[t]{0.5\textwidth}
\begin{minted}{Mathematica}
In[2]:= p1 = PermutationPlot[
{9,10,6,8,2,4,12,1,7,5,3,11},
DisplayFunction->Identity ];
\end{minted}
\end{minipage}
\end{tabular}
}
\vspace{1.5mm}

\justify
Sed efficitur diam eget ante elementum pharetra. Nullam dignissim pulvinar molestie. Sed dapibus tristique feugiat.

\end{document}

• What have you tried to achieve your result? For source code, you can use \texttt{}. You can also use the multicol package. See this question: tex.stackexchange.com/questions/3820/… – bmv Nov 29 '17 at 23:55
• tex.stackexchange.com/a/239912/11604 – Fran Nov 30 '17 at 1:44
• I’ve added my code so far – M.R. Nov 30 '17 at 1:47
• You could use the paracol package. I tried to create an answer, but I can't get minted to run, ever. – John Kormylo Nov 30 '17 at 3:08

No package necessary. Make it a 2-column table.

\documentclass{article}
\usepackage[margin=1.25in]{geometry}
\begin{document}
\noindent We restrict the inputs of our sorting functions to permutations of the numbers $1\dots n$. A simple way to visualize the amount of sortedness'' in such a list of numbers is a picture obtained with \texttt{ListPlot}.

${\footnotesize \begin{tabular}{@{}p{2.25in}@{\hspace{.25in}}p{3.5in}} This definition is used to plot permutations of the numbers 1\dots n with suitable settings of graphics options.&% \begin{tabular}[t]{r@{}l@{}}\verbIn[1]:= & \verbPermutationPlot[1_List, opts___] :=\\% &\hspace{.2in}\verbListPlot[ 1,\\% &\hspace{.4in}\verbPlotRange -> { {0.5,Length[1]+0.5},\\ &\hspace{.4in}\hphantom{\texttt{PlotRange -> ( }}\verb{0.5,Length[1]+0.5} },\\ &\hspace{.4in}\verbPlotStyle->PointSize[0.75/Length[1]],\\ &\hspace{.4in}\verbopts, Axes->None, FrameTicks->None,\\ &\hspace{.4in}\verbFrame->True,AspectRatio->1 ] \end{tabular} \\ \rule{0pt}{4ex}Here is a random permutation.&% \begin{tabular}[t]{r@{}l@{}}\verbIn[2]:= & \verbPermutationPlot[\\% &\hspace{.2in}\verb{9, 10, 6, 8, 2, 4, 12, 1, 7, 5, 3, 11},\\% &\hspace{.2in}\verbDisplayFunction->Identity ]; \end{tabular} \end{tabular}}$
\end{document}

• Thanks @Sandy G, this is almost perfect, but I'd like to keep the SourceCodePro font for the code and syntax highlighting from minted. – M.R. Nov 30 '17 at 3:21
• Looks like your update has what you want. – Sandy G Nov 30 '17 at 3:36
• But it is clunky, I like how your code is shorter and nicer. – M.R. Nov 30 '17 at 5:15