I would like to create vertical rules for indentation with algorithmic package. I applied the solution proposed here How can I create vertical lines indentation in algorithm pseudo code correctly without end keywords?
However, when I applied this solution I get dashed vertical lines as follows:
and the amount of dashes increase as the code increase.
My LaTeX code is the following:
\documentclass[12pt,journal,compsoc,onecolumn]{IEEEtran}
\usepackage[lite,subscriptcorrection,slantedGreek,nofontinfo]{mtpro2}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{etoolbox}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
% start with some helper code
% This is the vertical rule that is inserted
\newcommand*{\algrule}[1][\algorithmicindent]{%
\makebox[#1][l]{%
\hspace*{.2em}% <------------- This is where the rule starts from
\vrule height .75\baselineskip depth .25\baselineskip
}
}
\newcount\ALG@printindent@tempcnta
\def\ALG@printindent{%
\ifnum \theALG@nested>0% is there anything to print
\ifx\ALG@text\ALG@x@notext% is this an end group without any text?
% do nothing
\else
\unskip
% draw a rule for each indent level
\ALG@printindent@tempcnta=1
\loop
\algrule[\csname ALG@ind@\the\ALG@printindent@tempcnta\endcsname]%
\advance \ALG@printindent@tempcnta 1
\ifnum \ALG@printindent@tempcnta<\numexpr\theALG@nested+1\relax
\repeat
\fi
\fi
}
% the following line injects our new indent handling code in place of the default spacing
\patchcmd{\ALG@doentity}{\noindent\hskip\ALG@tlm}{\ALG@printindent}{}{\errmessage{failed to patch}}
\patchcmd{\ALG@doentity}{\item[]\nointerlineskip}{}{}{} % no spurious vertical space
% end vertical rule patch for algorithmicx
\makeatother
\begin{document}
\begin{algorithm}
\caption{Arbitrary Algorithm}\label{IS}
\begin{algorithmic}[1]
\Require A matrix $\mathbf{A}$ of size $m\times n$.
\Ensure Something.
\For{$i$ in $m$}
\For{$j$ in $n$}
\If{$i=j$}
\State Select a random action
\Else
\If{$i=j+1$}
\State Stay silent
\Else
\State Break
\EndIf
\EndIf
\EndFor
\EndFor
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{\textsc{Increase Algorithm}}
\label{algo:ffig}
\begin{algorithmic}[1]
\Require{$T$.}
\Ensure{A pair.}
\For{$\ell\gets1$ \textbf{to} $L$}
\For{$t\gets1$ \textbf{to} $T$}
\State $x_\ell^t\gets 0$
\EndFor
\EndFor
\For{$\ell\gets 1$ \textbf{to} $L$}
\For{$t\gets1$ \textbf{to} $T$}
\State $x_\ell^t\gets 1$
\State $S_\ell^t\gets 0$
\For{$\ell'\gets1$ \textbf{to} $L$}
\State $S_\ell^t\gets S_\ell^t + t$
\EndFor
\EndFor
\EndFor
\State \Return The solution
\end{algorithmic}
\end{algorithm}
\end{document}
