2

I have a problem in the width of the algorithm which I wrote as shown below, and I need to write it in a better way but I can't, any help?

enter image description here

This is my code:

  \begin{algorithmic}
  \WHILE{$GenC[i] ! = null$}
  \STATE $SpkRealC1 = GetSpikesInfo(GenC[i],RealC[1])$
  \STATE $SpkRealC2 = GetSpikesInfo(GenC[i],RealC[2])$
  \STATE $SpkRealC3 = GetSpikesInfo(GenC[i],RealC[3])$

  \STATE $MappedRealtoGenClass[i] = $
  \STATE $MaxSpikeNo(SpkRealC2,SpkRealC2,SpkRealC3)$
  \STATE $MappedRealtoGenClassRatio[i]=$
  \STATE $MaxSpikeNo(SpkRealC2,SpkRealC2,SpkRealC3)/spikesCount(GenClass[i])$
  \ENDWHILE
  \end{algorithmic}
2
  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). Apr 11, 2013 at 3:59
  • Please include a complete compilable document. Your algorithmic environment isn't in the article document class, for example. And please, please do not use math mode for text. It makes eyes bleed. Apr 11, 2013 at 4:04

1 Answer 1

2

You are setting the entire line as inline mathematics, which only breaks at specific locations (operators and relations). And, it would only do that if the penalty for breaking is not too high. In your instance (based on the line width and font size), the penalty is probably too high, so there's no appropriate breaking point.

Regardless, your use of text and math is not correct. Internally, $xyz$ is set as "x multiplied by y multiplied by z", which is correct. However, you don't $SpkReal$ to be set as the multiplication of symbols/variables S, p, k, R, e, a and l. Instead use something like \textrm{SpkReal}. I've done this in the following example (in a way by means of \algvar), including using some manual line breaking and indentation:

enter image description here

\documentclass{article}
\usepackage{algorithmic}% http://ctan.org/pkg/algorithmic
\newcommand{\algvar}{\textrm}
\begin{document}
\begin{algorithmic}
  \WHILE{$GenC[i] ! = null$}
  \STATE $SpkRealC1 = GetSpikesInfo(GenC[i],RealC[1])$
  \STATE $SpkRealC2 = GetSpikesInfo(GenC[i],RealC[2])$
  \STATE $SpkRealC3 = GetSpikesInfo(GenC[i],RealC[3])$

  \STATE $MappedRealtoGenClass[i] = $
  \STATE $MaxSpikeNo(SpkRealC2,SpkRealC2,SpkRealC3)$
  \STATE $MappedRealtoGenClassRatio[i]=$
  \STATE $MaxSpikeNo(SpkRealC2,SpkRealC2,SpkRealC3)/spikesCount(GenClass[i])$
  \ENDWHILE
\end{algorithmic}

\begin{algorithmic}
  \WHILE{$\algvar{GenC}[i] \neq \algvar{null}$}
  \STATE $\algvar{SpkRealC}_1 = \algvar{GetSpikesInfo}(\algvar{GenC}[i],\algvar{RealC}[1])$
  \STATE $\algvar{SpkRealC}_2 = \algvar{GetSpikesInfo}(\algvar{GenC}[i],\algvar{RealC}[2])$
  \STATE $\algvar{SpkRealC}_3 = \algvar{GetSpikesInfo}(\algvar{GenC}[i],\algvar{RealC}[3])$

  \STATE $\algvar{MappedRealtoGenClass}[i] = $
    \STATE \hspace*{\algorithmicindent}$\algvar{MaxSpikeNo}(\algvar{SpkRealC}_2,\algvar{SpkRealC}_2,\algvar{SpkRealC}_3)$
  \STATE $\algvar{MappedRealtoGenClassRatio}[i] = $
    \STATE \hspace*{\algorithmicindent}$\algvar{MaxSpikeNo}(\algvar{SpkRealC}_2,\algvar{SpkRealC}_2,\algvar{SpkRealC}_3)/$
    \STATE \hspace*{2\algorithmicindent}$\algvar{spikesCount}(\algvar{GenClass}[i])$
  \ENDWHILE
\end{algorithmic}
\end{document}

You must log in to answer this question.

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