如何实现这两列的样式?

如何实现这两列的样式?

我想添加一些两列形式的代码示例。左边是描述,右边是 REPL 输入代码和输出。

下面是我想要实现的一个示例:

在此处输入图片描述

是否有适合此类环境的知名软件包?

更新:

这是我到目前为止尝试过的,但是相当混乱:

在此处输入图片描述

以下是 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} 

答案1

无需任何包装。将其设为 2 列表格。

在此处输入图片描述

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

相关内容