Hi I am trying to write an algorithm which looks something like the image below:


I was wondering how to write the "Step 1 (Update)" and also the rest of the line which says "When an edge e...." should all that be inside the math symbols i.e.. \[\] ??

I am kinda new to latex. Thanks for the help!

Also I was wondering what is the difference between algorithm and algorithmic?


1 Answer 1


Here you go:



\underline{\sf Step 1 (Update):} When an edge $e=\{u,v\}\in E[G]$ arrives, update each $Z_{\smallarrowover{ab}}$ w.r.t.
Z_{\smallarrowover{ab}}(G)\leftarrow Z_{\smallarrowover{ab}}+\mathcal M_{\smallarrowover{ab}}(u,v)+\mathcal M_{\smallarrowover{ab}}(v,u).


This is the result:

enter image description here

Initially I used \vec{ab} for the arrow over ab, but that did not stretch, and putting \overrightarrow{ab} in the subscripts did not make it smaller, as you want. So I defined a new command, which needs the \graphicx package. Also, you might not need the \noindent I have at the beginning, depending on what you have before it. I put it there so the whole thing would fit on one line.

P.S. I have no experience with the algorithm or algorithmic environments.

  • 1
    I think the OP was probably asking about the difference between the algorithm and algorithmic environments. Commented Apr 19, 2014 at 20:12
  • Yes, I meant the \begin{algorithm} and \begin{algorithmic} commands
    – Yathi
    Commented Apr 19, 2014 at 20:15
  • Also when I try the above code I am getting: 'Missing $ inserted. <inserted text> $ l.109 ...ives, update each $Z_{\smallarrowover{ab} }$ w.r.t. '
    – Yathi
    Commented Apr 19, 2014 at 20:16
  • @Yathi what document class are you using, and which packages do you have loaded? Commented Apr 19, 2014 at 20:19
  • Hi.. This is the start of my report: \documentclass{acm_proc_article-sp} \usepackage{amsmath} \usepackage{algorithm} \usepackage{graphicx} \newcommand\smallarrowover[1]{\scalebox{.5}{\overrightarrow{#1}}} \usepackage[noend]{algpseudocode} \begin{document}
    – Yathi
    Commented Apr 19, 2014 at 20:22

You must log in to answer this question.

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