0

I am using algpseudocode to write pseudo code. I am noticed that the pseudo code is justify aligned, which doesn't look good here. Below is the snippet of latex code-

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\begin{algorithm}
\caption{Generate Random Slides}
\label{algo:slide_generator}
\begin{algorithmic}[1]
    \Procedure{SlideGenerator}{}
    \State Let ${array\_temp}$ is a new list of length $\gets {array\_alph}.Length$
    \State  Let ${array\_slides}$ is a new list of length $\gets {array\_alph}.Length$
    \For{$i = 0 \to \textit{array\_alph}.Length$}
        \State $first\_char\_per\_slide \gets getUniqueChar(array\_temp)$
        \Comment Get unique character from ${array\_alph}$ which is not present in ${array\_temp}$
        \State $unique\_alph.Add(first\_char\_per\_slide)$
            \While{$used\_alph.Length < items\_per\_slide$}
                \State $unique\_alph.Add(getUniqueChar(unique\_alph))$
                \Comment Get unique character from $unique\_alph$ and add it to $unique\_alph$
            \EndWhile
    \EndFor
    \State $array\_slides [i] \gets current\_slide(unique\_alph)$
    \State $array\_temp.Add(first\_char\_per\_slide)$\\
    \Return $array\_slides$
    \EndProcedure
\end{algorithmic}
\end{algorithm}

Below is the screenshot of generated pdf-

enter image description here

I have following two questions-

  1. How to correct the alignment?
  2. Since the pseudo code is not looking better, How to modify the content of it?

I have the above code in C# But somehow I am not able to write a proper pseudo code. The above pseudo code uses System.Collections.Generic.List

ravi
  • 1,618
  • ...your "second question" is not very clear. – Werner Sep 25 '14 at 17:23
  • @Werner: My second question is more about writing beautiful pseudo code. As you can see in the above screenshot, the pseudo code is not looking good. Can you suggest some quick modifications? Like how an array and list should be defined in pseudo code. array_temp is a List here. Also should I replace following in line 10? add first_char_per_slide to array_temp – ravi Sep 26 '14 at 04:27
  • @RaviJoshi Please complete your example in order to make it compilable. It seems quite narrow in your screenshot. Are you talking about alignment on the left (like in Werner's link) or about the justified printing? The second question and your comment are off topic. I think you won't get help on how to formulate pseudo code here. It would be a bit like "How may I set that formula for my thesis and please check, if it is mathematically correct‽" You should look for a C# or code review stack exchange and ask there. – LaRiFaRi Sep 26 '14 at 05:54
  • 1
    @LaRiFaRi: In my first question I am talking about Justify printing, which I have mentioned in the post. I followed the Werner's link and changed font to \small so that worked :) . As per your suggestion, I should ask the second question in Code Review – ravi Sep 26 '14 at 06:24

0 Answers0