I want to produce an algorithm style such that it is centered on the page, numbered and also that the horizontal lines do not extend unnecessarily as shown in the image. Is there any way using the algorithm package?
enter image description here

  • 2
    Welcome to TeX.SE! Can you please show us what you have tried so far? Then we do not have to guess what you are doing ...
    – Mensch
    Jul 6, 2021 at 19:33
  • 2
    The algorithms package separates the formatting from the float environment, allowing more control over margins etc. Jul 6, 2021 at 19:39
  • 2
    I use the package algorithm2e, as it is quite flexible. The resulting floats can be placed at will.
    – vonbrand
    Jul 6, 2021 at 22:48
  • Problem solved? Nov 23, 2021 at 6:47

1 Answer 1


Just for fun (after 15 minutes) I hope that this MWE is the same (without the mistakes of symbols) of your figure.....

%% Compile and read me!


  \caption{Gradient Descent}
    \Procedure{Gradient Descent}{$\{(\mathbf{X}_i,Y_i)\}_{i\in \text{train}},Ep,\eta,\lambda,\alpha,\mathbf{w}_0$}
    \State $\mathbf{w}\leftarrow \mathbf{w}_0.$
    \For{$i \in\{1,\ldots Ep\}$}
    \State $\mathbf{w}\leftarrow \mathbf{w}-\eta(\nabla_{\mathbf{w}}MSE(c_{\mathbf{w}})+\lambda\mathbf{w})+\alpha\Delta(\mathbf{w}).$
    \State{\textbf{Return} \textbf{w}.}

enter image description here

  • When I use \documentclass{ieeeaccess} class, 1st procedure line did not fit into the first line, is there any way to change font size or spacing slightly to make it fit?
    – alper
    Dec 9, 2022 at 16:50
  • @alper Can you ask a new question with your minimal working example, please?
    – Sebastiano
    Dec 9, 2022 at 17:39

You must log in to answer this question.

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