0

How can I write code like this in latex or overleaf? enter image description here

3
  • Welcome to TeX Stack Exchange! There are certain packages as listings or minted that achieve what you want. Dec 14, 2020 at 17:07
  • 1
    Have a look at ctan.org/pkg/listings Dec 14, 2020 at 17:07
  • 2
    This seems to have been obtained with algorithm2e.
    – Bernard
    Dec 14, 2020 at 17:15

1 Answer 1

2

Use algorithm2e:

enter image description here

\documentclass{article}

\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\DontPrintSemicolon
\SetKwInput{Input}{Input}
\SetKwInput{Output}{Output}
\SetKw{To}{ to }
\SetKw{Print}{Print }

\begin{document}

\begin{algorithm}
  \caption{PrintK}
  \Input{Integers $n_1, n_2, \ldots, n_m$ each of which is $\geq 1$}
  \Output{None}
  $k \gets 0$\;
  \For{$i_1 \gets 1 \To n_1$}{%
    \For{$i_2 \gets 2 \To n_2$}{%
      $\cdot$\;
      $\cdot$\;
      $\cdot$\;
      \For{$i_m \gets 1 \To n_m$}{%
        $k \gets k + 1$\;
      }
    }
  }
  \Print $k$
\end{algorithm}

\end{document}
1
  • Thank you very much Dec 15, 2020 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .