TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Welcome to TeX.SX! – Heiko Oberdiek Apr 19 '14 at 19:48
See section 1 of the algorithms bundle documentation: algorithm is to algorithmic as table is to tabular. – Ian Thompson Apr 19 '14 at 20:34
Awesome! Thanks @IanThompson – Yathi Apr 19 '14 at 21:05
up vote 3 down vote accepted

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.

share|improve this answer
I think the OP was probably asking about the difference between the algorithm and algorithmic environments. – Ian Thompson Apr 19 '14 at 20:12
Yes, I meant the \begin{algorithm} and \begin{algorithmic} commands – Yathi Apr 19 '14 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 Apr 19 '14 at 20:16
@Yathi what document class are you using, and which packages do you have loaded? – jlv Apr 19 '14 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 Apr 19 '14 at 20:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.