TransWikia.com

Uses only half the page / Right side of the page empty

TeX - LaTeX Asked by Santeau on July 15, 2021

I’m very new to Tex, I’m trying to write an algorithm using LaTeX on Overleaf but only the left half of the page is used while the rest of the line is sent to the next line.

enter image description here

Can you tell me what did I do wrong ?


 documentclass{IEEEtran}
 usepackage{algorithmic}
 begin{document}
 %begin{algorithm}
 %caption{Algorithm for ...}
 textbf{Algorithm:GraphPaths(capital,Cryptocurrencies[])}
 begin{algorithmic}[1]
 renewcommand{algorithmicrequire}{textbf{Input:}}
 renewcommand{algorithmicensure}{textbf{Output:}}
 REQUIRE capital, Cryptocurrencies [];
 ENSURE  Augmenting paths and total arbitrage
  textit{Initialisation} :
 STATE Path = [];
FOR {$i$ in $Currencies$ }
    WHILE{$Currencies_i.market[0]$textless$Currencies_i.market[n]$:}
        STATE volume = min($market_i_0$, $market_i_n$, $capital$);
        STATE $market_i_0$, $market_i_n$-=volume;
        IF {capitaltextgreater volume}
            STATE capital = capital-volume+volumecdot($market_i_n.price$- $market_i_0.price$);
        ELSE capital+=volumecdot($market_i_n$.price - $market_i_0$.price);
        STATE Path.add{$Currencies_i.market[0]$,$Currencies_i.market[n]$}
        IF {$market.volume$ $leq$ 0 in $Currencies$:}
            STATE remove: $.market[x]$;
 
ENDFOR

 RETURN {Path, capital}
 end{algorithmic} 
 %end{algorithm}
 end{document}

2 Answers

The issue stems from not closing the structures within your algorithm. That is, IFs should have a closing ENDIF, WHILEs should have a closing ENDWHILE and FORs should have a closing ENDFOR. Additionally, you can't have double subscripts of the form a_b_c; instead you're probably after a_{b_c}. Finally, cdot is a math symbol and can therefore only be used within $...$.

enter image description here

documentclass{IEEEtran}

usepackage{algorithmic}
renewcommand{algorithmicrequire}{textbf{Input:}}
renewcommand{algorithmicensure}{textbf{Output:}}

newcommand{NONUMSTATE}{item[]}
newcommand{VAR}{textnormal}
newcommand{minusbecomes}{mathrel{{-}{=}}}
newcommand{plusbecomes}{mathrel{{+}{=}}}

begin{document}

noindent
textbf{Algorithm: GraphPaths(capital,Cryptocurrencies [])}

begin{algorithmic}[1]
  REQUIRE capital, Cryptocurrencies [];
  ENSURE  Augmenting paths and total arbitrage
  
  NONUMSTATE textit{Initialisation}:
  
  STATE Path = [];
  FOR {$i$ in $VAR{Currencies}$}
    WHILE{$i.VAR{market}[0] < .VAR{market}[n]$}
      STATE $VAR{volume} = min(VAR{market}_{i_0}, VAR{market}_{i_n}, VAR{capital})$;
      STATE $VAR{market}_{i_0}, VAR{market}_{i_n} minusbecomes VAR{volume}$;
      IF {$VAR{capital} > VAR{volume}$}
        STATE $VAR{capital} plusbecomes 
          VAR{capital} - VAR{volume} + VAR{volume} cdot (VAR{market}_{i_n}.VAR{price} - VAR{market}_{i_0}.VAR{price})$;
      ELSE
        STATE $VAR{capital} plusbecomes VAR{volume} cdot (VAR{market}_{i_n}.VAR{price} - VAR{market}_{i_0}.VAR{price})$;
      ENDIF
      STATE Path.add $i.VAR{market}[0], i.VAR{market}[n]$
      IF {$VAR{market}.VAR{volume} leq 0$ in $VAR{Currencies}$}
        STATE remove $.VAR{market}[x]$;
      ENDIF
    ENDWHILE
  ENDFOR

  RETURN Path, capital
end{algorithmic} 

end{document}

I've also introduces some minor changes to your coding style, just to provide consistency.

Correct answer by Werner on July 15, 2021

I think my mistake was to use the "-" symbol from my keyboard that seems to be an incorrect way to do subtraction in LaTeX.

I used textminus and it worked perfectly, it was really a newbie issue, I hope that helps anyone facing in the same issue.

Answered by Santeau on July 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP