2

I'm referring to the pdf linked here.

Specifically, how can I recreate this part on the first page?

enter image description here

I'm guessing it's using the verbatim environment somehow, but how can I get those vertical lines in there too? Thanks in advance.

User
  • 23
  • Please make an image screenshot of the specific part you are asking for, an embed it into your question. – Matsmath Jul 05 '16 at 04:00
  • @Matsmath done! I wasn't aware you could add a screenshot, thanks! – User Jul 05 '16 at 04:02
  • Possibly related: http://tex.stackexchange.com/questions/292815/how-can-i-create-vertical-lines-indentation-in-algorithm-pseudo-code-correctly-w – Christian Jul 05 '16 at 06:27
  • An overview on different packages for algorithms can be found in the following question: http://tex.stackexchange.com/questions/229355/algorithm-algorithmic-algorithmicx-algorithm2e-algpseudocode-confused – Christian Jul 05 '16 at 08:01
  • Perhaps this: http://tex.stackexchange.com/questions/172981/pseudo-code-with-vertical-line – Steven B. Segletes Jul 06 '16 at 10:39

2 Answers2

3

A quick solution based on the package documentation for algorithm2e

\documentclass{standalone}
\usepackage{algorithm2e}

\begin{document}
\begin{algorithm}[H]
  \SetStartEndCondition{ }{}{}%
  \SetKwProg{Fn}{def}{\string:}{}
  \SetKwIF{If}{ElseIf}{Else}{if}{:}{elif}{else:}{}%
  \SetKwFunction{FnFoo}{foo}
  \DontPrintSemicolon
  \SetAlgoLined

  \Fn{\FnFoo{}}{
    \If {something}{
      \FuncSty{Do} something\;
      \FuncSty{Do} something\;
    }
    \FuncSty{Do} something last\;
  }
\end{algorithm}
\end{document}

which produces Algorithm created with algorithm2e

Christian
  • 1,012
2

Uses my answer at pseudo code with vertical line, modified to make rules gray in color.

\documentclass{article}
\usepackage{xcolor}
\def\lindent{.5ex}
\def\rindent{2ex}
\def\rthk{1.5pt}
\newcommand\block[3]{\unskip%
  \noindent\parbox[b]{\textwidth}{\strut\ignorespaces#1\strut}\\
  \setbox0=\hbox{\parbox[b]{\textwidth}{\strut\ignorespaces#2\strut}}%
  \hspace*{\lindent}\textcolor{gray!50}{\rule[-.5\dp\strutbox]{\rthk}{\ht0}}%
  \hspace{\rindent}\box0\\\parbox[b]{\textwidth}{\strut\ignorespaces#3\strut}%
\ignorespaces}
\begin{document}
\ttfamily
\block{
def foo():
}{
  \block{
  if something
  }{
    do something\\
    do more things
  }{
  do something last}
}
{}
\end{document}

enter image description here