我寫的演算法的寬度有問題,如下所示,我需要以更好的方式編寫它,但我不能,有什麼幫助嗎?
這是我的程式碼:
\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}
答案1
您將整行設定為內聯數學,它僅在特定位置(運算符和關係)中斷。而且,只有在破壞懲罰不太高的情況下才會這麼做。在您的實例中(基於線寬和字體大小),懲罰可能太高,因此沒有合適的斷點。
無論如何,您對文字和數學的使用是不正確的。在內部,$xyz$
設定為“x
乘以y
” z
,這是正確的。但是,您不能將其設定為符號/變數, , , , ,和 的$SpkReal$
乘法。相反,使用類似.我在以下範例中完成了此操作(以某種方式),包括使用一些手動換行和縮排:S
p
k
R
e
a
l
\textrm{SpkReal}
\algvar
\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}