Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass[final,5p,times,twocolumn,authoryear]{elsarticle}
- \usepackage{algorithm}
- \usepackage{algpseudocode}
- \usepackage{etoolbox}
- \usepackage{lipsum}
- \usepackage{amsmath,amsfonts,amssymb,yfonts}
- \usepackage{cleveref}
- % Creating new commands...
- \newcommand{\Test}{$\mathcal{D}_{i^{\ast}\xi\textfrak{N}^{i^{\ast}}}$}
- % Patch to correct the way of vertical lines are align or arranged throughout the code using long texts in a line, becouse theses ones is broken due to long texts. This is solution provid by <https://tex.stackexchange.com/a/524700/155670>.
- \makeatletter
- % start with some helper code
- % This is the vertical rule that is inserted
- \newcommand*{\algrule}[1][\algorithmicindent]{%
- \hspace*{.2em}% <------------- This is where the rule starts from
- \vrule %height .75\baselineskip depth .25\baselineskip
- \hspace*{\dimexpr#1-.2em-.4pt}%
- }
- \newcommand{\StatePar}[1]{%
- \State\parbox[t]{\dimexpr\linewidth-\ALG@thistlm}{\strut #1\strut}%
- \vspace{-\lineskip}
- }
- \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
- % Add \struts to keywords
- \algrenewcommand\algorithmicend{\strut\textbf{end}}
- \algrenewcommand\algorithmicdo{\strut\textbf{do}}
- \algrenewcommand\algorithmicwhile{\strut\textbf{while}}
- \algrenewcommand\algorithmicfor{\strut\textbf{for}}
- \algrenewcommand\algorithmicforall{\strut\textbf{for all}}
- \algrenewcommand\algorithmicloop{\strut\textbf{loop}}
- \algrenewcommand\algorithmicrepeat{\strut\textbf{repeat}}
- \algrenewcommand\algorithmicuntil{\strut\textbf{until}}
- \algrenewcommand\algorithmicprocedure{\strut\textbf{procedure}}
- \algrenewcommand\algorithmicfunction{\strut\textbf{function}}
- \algrenewcommand\algorithmicif{\strut\textbf{if}}
- \algrenewcommand\algorithmicthen{\strut\textbf{then}}
- \algrenewcommand\algorithmicelse{\strut\textbf{else}}
- \algrenewcommand\algorithmicrequire{\strut\textbf{Input:}}
- \algrenewcommand\algorithmicensure{\strut\textbf{Output:}}
- \let\oldState\State
- \renewcommand{\State}{\oldState\strut}
- \begin{document}
- \begin{align}
- a & = b \label{eq:1}
- \end{align}
- % ---> Algorithm 01.
- \begin{algorithm}
- \caption{Arbitrary Algorithm}
- \begin{algorithmic}[1]
- \Require A matrix $\mathbf{A}$ of size $m\times n$.
- \Ensure Something.
- \Procedure{MainProcedure}{}
- \State $a\gets{}b$
- \For{$i$ in $m$}
- \For{$j$ in $n$}
- \showoutput
- \If{$i = j$}
- \State Obtain \Test
- \State $\textfrak{M}^{(l)}$
- \State $\textfrak{M}^{(l)}$
- \State $\displaystyle{\sum_{i=1}^{c}{\alpha^{(b^{\ast})}}}$
- \State According to \cref{eq:1}
- \State According to \cref{eq:1}
- \State According to \cref{eq:1}
- \State $\beta = \displaystyle{\max_{i=1}^{c}\!\left(\alpha^{(\beta^{\ast})}\right)}$
- \StatePar{Select a random action. \lipsum[1]}
- \Else
- \If{$i = j + 1$}
- \State Stay silent
- \Else
- \State Break
- \algstore{bkbreak}
- \end{algorithmic}
- \end{algorithm}
- % ---> Algorithm 01: continuation.
- \begin{algorithm}
- \begin{algorithmic}
- \algrestore{bkbreak}
- \EndIf
- \EndIf
- \EndFor
- \EndFor
- \ForAll{condition}
- \EndFor
- \EndProcedure
- \end{algorithmic}
- \end{algorithm}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement