5

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

Algorithm

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?

3

Here you go:

\documentclass{article}
\usepackage{graphicx}
\newcommand\smallarrowover[1]{\scalebox{.5}{$\overrightarrow{#1}$}}

\begin{document}

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

\end{document}

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. – 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? – Jānis Lazovskis 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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