如何使用套件algorithm2e排版ac風格函數?

如何使用套件algorithm2e排版ac風格函數?

我對乳膠中的類型設定演算法非常陌生。以下是我第一次嘗試使用套件 Algorithm2e 排版簡單的 C 風格函數:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[ruled]{algorithm2e}
\title{algorithm}
\author{Imran Ali}
\date{June 2017}

\begin{document}
\SetStartEndCondition{(}{)}{)}\SetAlgoBlockMarkers{}{\}}%
\SetKwFunction{Square}{square}%
\SetKwBlock{square}{\{}{}%
\AlgoDisplayBlockMarkers\SetAlgoNoLine%
\begin{algorithm}
\Square(int x)
    \square{%
       result = x ** 2 \;
        }
        \KwRet{result} 
    }
\caption{C style function}
\end{algorithm}
\end{document} 

產生以下結果在此輸入影像描述 目前乳膠編譯器正在抱怨:

!額外 } 或忘記 \endgroup

如果社群能夠指出如何正確實現結果,我將不勝感激。

相關內容