I'm writing pseudo code within an "algorithmic" environment. I'd like to have two columns within the algorithm. The left column should the standard constructs such as
\STATE
, \IF
, etc. The right column should have explanatory text.So I'm looking for something like this as output:
Code: Select all
1: if (x<3) O(1)
2: f(x) O(x^2)
3: else
4: g(x) O(x!)
5: end if
6: y = 2 * x O(1)
So two kinds of alignment are important: each item in the right-hand column must be vertically aligned with its counterpart on the left, and every entry in the right-hand column should be left-justified along the same (invisible) vertical line.
Is there a clean way to do this in LaTex?
I've tried having "array" or "tabularx" environments inside, or around, the "algorithmic" environment, but that seems to make LaTeX deeply unhappy.
I'm okay with manually calculating what offset the right-hand column should start at relative to something like the page's left margin. But I can't figure out how to implement that kind of alignment. I.e., I can't figure out how to write something like "\hspace{5 in from left margin of page}".