2

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:

enter image description here

Are there well known packages for this type of environment?

Update:

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

enter image description here

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} 
4

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

enter image description here

\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@{}}\verb`In[1]:= `& \verb`PermutationPlot[1_List, opts___] :=`\\%
    &\hspace{.2in}\verb`ListPlot[ 1,`\\%
    &\hspace{.4in}\verb`PlotRange -> { {0.5,Length[1]+0.5},`\\
    &\hspace{.4in}\hphantom{\texttt{PlotRange -> ( }}\verb`{0.5,Length[1]+0.5} },`\\
    &\hspace{.4in}\verb`PlotStyle->PointSize[0.75/Length[1]],`\\
    &\hspace{.4in}\verb`opts, Axes->None, FrameTicks->None,`\\
    &\hspace{.4in}\verb`Frame->True,AspectRatio->1 ]`
\end{tabular}
\\
\rule{0pt}{4ex}Here is a random permutation.&%
\begin{tabular}[t]{r@{}l@{}}\verb`In[2]:= `& \verb`PermutationPlot[`\\%
    &\hspace{.2in}\verb`{9, 10, 6, 8, 2, 4, 12, 1, 7, 5, 3, 11},`\\%
    &\hspace{.2in}\verb`DisplayFunction->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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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