How can I format the algorithm shown in the following image without using the algorithm environment nor tabular environment and how can I make the proper cross-reference so that \ref{Algorithm 2} may be turned into a hyperlink to the algorithm itself.

enter image description here

  • 2
    What is reason of not using algorithm like environments here?
    – user31729
    Commented Aug 28, 2017 at 10:27
  • 3
    While you wait for an answer to this question, can you go back to your previous ones and look if the answers solve your problems and accept them, if they do? Commented Aug 28, 2017 at 10:38
  • @christian Hupfer, I am writing a one column format of a paper to be send to an elsevier journal and my algorithm is too long (3 pages) and using the algorithm environment causes problem when I try to split the algorithm.
    – user137684
    Commented Aug 28, 2017 at 10:59
  • 2
    @user137684: That's an explanation that should have been done in the post ;-)
    – user31729
    Commented Aug 28, 2017 at 11:14

1 Answer 1

  • To get multi-level indentation, I would suggest to use the enumitem package: Define a new type of list (say level) that has no item symbol, and thus only provides an indentation that can be nested.
  • To get user-defined references, you need to define a counter (say algo) and call \refstepcounter at the point where you want your reference to point to.

I combined these two things (together with horizontal lines) in a definition of a new environment àlgorithm:


    \paragraph{Algorithm \thealgo}#1%


We summarize the PF-EKF in Algorithm~\ref{algo:ekf}

\begin{algorithm}{Particle filter with EKF proposal}\label{algo:ekf}
    \item \textbf{Initialize:}
    \item Draw the particles by using $\{x_0^f\}_{i=1}^M\!\sim\!p(x_0)$
    \item \textbf{for} k=1 to N \textbf{do}
        \item \textbf{Prediction Step:}
        \item Draw the particles by using the Equation 52
        \item \textbf{Measurement Step:}
        \item Update the weight by using the Equation 56
        \item \textbf{Resample Step}
    \item end for


enter image description here

  • @ Tiuri, Is there a possibility to make the horizontal line to be as wide as it need in order to accommodate the content of the algorithm.
    – user137684
    Commented Aug 28, 2017 at 21:42
  • @user137684 No, I don't know a way of automatically achieving this with an itemize-type environment. But feel free to take the code of my answer and ask this as a new question.
    – Tiuri
    Commented Aug 29, 2017 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .