Insert algorithm in Lyx 2.1.1 with line numbers

7.6k views Asked by At

I am able to insert algorithms directly with Lyx 2.1.1 using insert->float->algorithm , however the algorithm lines are not numbered in the generated pdf. Is there any option that can number the algorithm lines or any work around to include algorithm in Lyx with line number? I am using the built in IEEE template document in Lyx and assume it should be possible with other templates too.

3

There are 3 answers

2
Werner On

The default algorithm insertion is just a floating environment. If you want a built-in numbered algorithm, you have to consider adding the algorithm2e module:

enter image description here

Then, also add \LinesNumbered to your Document > Settings... > LaTeX Preamble.

enter image description here

The above assumes a non-ERT approach to numbered-line algorithms. Of course, if you wish, you can go all out with LaTeX ERT to obtain line numbers in algorithms.

0
MSIS On

I think a better way is to even use the package algorithmic by adding the following in Documents -> Settings... -> LaTex Preambule:

\usepackage{algorithmic}

And then, inside the default Algorithm float as Tex Code:

\begin{algorithmic}[1]

\STATE example line that will be numbered

\end{algorithmic}

This solved the problem for me. I hope it does the same for you!

0
Jaleks On

After having inserted the float, you should additionally insert a program listing environment. In the settings dialog of it (which you reach through the context menu of the listing), you can set numbering, highlighting and the other most important things the LaTeX package 'lstlistings' supports. (Rest of the settings can put in into the second tab of the dialog)