1

I am a beginner in writing algorithm in LaTeX using algorithm2e. I am trying to write a simple algorithm (code is attached herewith). However, I am not getting correct output. I want to see line numbers. The output is also attached herewith.

Please note that i included the following command in LaTeX preamble too see line numbers

\usepackage[linesnumbered,lined,boxed,commentsnumbered]{algorithm2e}

There must be something wrong in my code. Is there anyone who can help me execute it correctly?

Output produced

\begin{algorithm} [H]
\caption{QL algorithm}
Initialize Q-table values (Q(s, a)) arbitrarily\
Initialize a state(s_t)\
Repeat Step 4 to 6 until learning period ends\
Choose an action (a_t) for the current state (s_t) using an exploratory policy\
Take action (a_t) and observe the new state (s_t+1) and reward (r_t+1)\
Update Q-value\
\end{algorithm}
2
  • 1
    Welcome to TeX.SE! Please extend your code fragment to complete small document, which begin with \documentclass and end with \end{document} Commented Dec 23, 2019 at 1:36
  • 1
    The problem might only come from the subscripts, which should probably be in math mode. Commented Dec 23, 2019 at 2:44

1 Answer 1

5

This is how you would set things up using algorithm2e. Specifically, you need line-ends to be denoted by \;. Also consider using labels (\nllabel) and that you can \reference.

enter image description here

\documentclass{article}

\usepackage[linesnumbered,lined,boxed,commentsnumbered]{algorithm2e}

\begin{document}

\begin{algorithm}
  \caption{QL algorithm}
  Initialize $Q$-table values $(Q(s, a))$ arbitrarily\;
  Initialize a state $(s_t)$\;
  Repeat Steps~\ref{alg:step_4} to~\ref{alg:step_6} until learning period ends\;
  Choose an action $(a_t)$ for the current state $(s_t)$ using an exploratory policy\; \nllabel{alg:step_4}
  Take action $(a_t)$ and observe the new state $(s_t + 1)$ and reward $(r_t + 1)$\;
  Update $Q$-value\; \nllabel{alg:step_6}
\end{algorithm}

\end{document}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.