在文本左侧插入垂直线

在文本左侧插入垂直线

在“article”环境中,使用以下代码(无序言):

\begin{document}
\begin{center}
    {\fontfamily{lmss}{\LARGE{Basic and Useful Tools in Python}}}
\end{center}

\setlength{\droptitle}{-4em}

\thispagestyle{fancy}

\section{Summations}
{\fontfamily{lmss}\selectfont
Codes within this section will involve summation in some way or another.
}
{\subsection{\small{Sum of first $n$ natural numbers}}}
{\fontfamily{lmss}\selectfont
Using the range command, we will have the following:}
\vspace{0.3cm}
\begin{lstlisting}[language=Python]
In [1]
def sum_of_the_first_n_positive_integers(n):
    output = 0
    for i in range(1,n+1):
        output = output + i
    return output

In [2] (Example)
sum_of_the_first_n_positive_integers(10)
\end{lstlisting}
\vspace{0.3cm}

{\fontfamily{lmss}\selectfont
An alternative method for this question will be simply using the summation formula:}
\vspace{0.3cm}
\begin{lstlisting}[language=Python]
In [1]
def sum_of_the_first_n_positive_integers_v2(n):
    return n*(n+1)//2

In [2] (Example)
sum_of_the_first_n_positive_integers_v2(10)
\end{lstlisting}
\vspace{0.3cm}
\end{document}

将为我们提供以下pdf:

我想知道如何在代码旁边插入垂直线,如下所示:

我正在使用“listings”包将 Python 代码插入到 latex 中。我尝试使用 warpfig 并插入一条直线的图像,但效果不太好。

相关内容