Basic IT Knowledge

Latex Algorithm - 공부하는 도비

DOVISH WISDOM 2022. 3. 22. 01:03  
728x90
반응형

내가 보려고 정리하는 Latex 사용법 - Algorithm 작성편 

 

\begin{algorithm}[h]
\label{Algorithm Label}
\SetKwInput{KwInput}{Input}                % Set the Input
\SetKwInput{KwOutput}{Output}              % set the Output
\DontPrintSemicolon
  
  \KwInput{Your Input}
  \KwOutput{Your output}
  \KwData{Testing set $x$}
\BlankLine
% Set Function Names
  \SetKwFunction{FMain}{Main}
  \SetKwFunction{FSum}{Sum}
  \SetKwFunction{FSub}{Sub}
 
% Write Function with word ``Function''
  \SetKwProg{Fn}{Function}{:}{}
  \Fn{\FSum{$first$, $second$}}{
        a = first\\
        b = second\\
        sum = first + second\\
        \KwRet sum\\
  }
  \\

% Write Function with word ``Def''
  \SetKwProg{Fn}{Def}{:}{}
  \Fn{\FSub{$first$, $second$}}{
        a = first\\
        b = second\\
        sum = first - second\\
        \KwRet sum\\
  }
  \\

  \SetKwProg{Fn}{Function}{:}{\KwRet}
  \Fn{\FMain}{
        a = 5\\
        b = 10\\
        Sum(5, 10)\\
        Sub(5, 10)\\
        print Sum, Sub\\
        \KwRet 0\\
  }
\caption{Algorithm Name}
\end{algorithm}