TransWikia.com

Align equation in algorithm

TeX - LaTeX Asked on September 10, 2020

I am using algorithm2e to try and write an algorithm with an equation. So far we’re looking at

title{AlgorithmTemplate}
documentclass[12pt]{article}
usepackage{fullpage}
usepackage{times}
usepackage{fancyhdr,graphicx,amsmath,amssymb,mathtools}
usepackage[ruled,vlined]{algorithm2e}
include{pythonlisting}
begin{document} 
begin{algorithm}[H]
caption{How to write algorithms}
SetAlgoLined
%KwIn{Data $mathcal{D}={mathbf{X} cup mathbf{y}}={(mathbf{x}_1,y_1),...,(mathbf{x}_N,y_N)}$}
SetKwInOut{Input}{Input}
Input{Data $mathcal{D}={mathbf{X} cup mathbf{y}}={(mathbf{x}_1,y_1),...,(mathbf{x}_N,y_N)}$;
Level-one learning algorithms $mathcal{L}_{1,1},...,mathcal{L}_{1,T_1}$;
Level-two learning algorithms
SetKwProg{proced}{Procedure}{:}{}
SetKw{KwBy}{by}
proced{}{
 For{$t in mathbb{N} cap [1,T_1]$}{
    $h^1_t gets mathcal{L}_{1,t}(mathcal{D})$
    }
 }

SetKwInOut{Output}{Output}
Output{begin{align}H(x) = h^3(h^2_1(h^1_1(x), &... ,h^1_{T_1}(x)), 
&shortvdotswithin{...} 
h^2_{T_2}(h^1_1(x), &... ,h^1_{T_1}(x)))end{align}}

 
end{algorithm}


end{document}

(copied from an algorithm template I found online)

That should run. Now at the bottom of the algo I end up with

enter image description here

As you can see, I’ve made an effort to align. But I want to make the following changes:

  1. the last line (third) shouldn’t be way below the first two
  2. I want to align the line starting $h^2_{T_2}$ to start exactly where $h^2_{1}$ starts
  3. I don’t want any numbers for these (doesn’t look good in an algorithm) i.e. no (1), (2), (3)
  4. I would like to get the first line starting right after Output:, i.e. " Output: H(x)=… " in line. Not starting spaced way underneath, and not centred. i.e., I want it look like my Input looks (if you run the code)

How can I achieve these changes?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP