TransWikia.com

The format of if-else in the function is wrong

TeX - LaTeX Asked on June 26, 2021

When using latex to write pseudo-code, using loops in the function, the vertical line position is wrong.

usepackage[ruled,lined]{algorithm2e}
usepackage{algorithmicx}  
usepackage{algpseudocode}  
begin{document}
    begin{algorithm} [t]
    
    begin{algorithmic}
            
    Function{victim_func1}{a}
    
    eIf{sec[i]}{
         A
    }{
         B
    }
    EndFunction
    
    end{algorithmic}
    end{algorithm}  
end{document}

The result displayed is:
enter image description here

The vertical line on the left should belong to if-else, but the position is wrong. How can I solve it? Thank you!

One Answer

algorithm2e provides a function environment. You can set the name of the function with caption (no underscores allowed!):

documentclass{article}
usepackage[ruled,lined]{algorithm2e}
begin{document}
  begin{function}caption{VictimFunc1(a)}
    eIf{sec[i]}{
       A
    }{
       B
    }
  end{function}  
end{document}

enter image description here

Correct answer by DG' on June 26, 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