Algorithm code width problem

Algorithm code width problem

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?

insira a descrição da imagem aqui

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}

Responder1

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:

insira a descrição da imagem aqui

\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}

informação relacionada