
라텍스에서 함수를 사용하여 의사 코드 조각을 어떻게 작성할 수 있는지 도와주세요.
\begin{algorithmic}
\STATE $\mathrm{maxWeight} \leftarrow \mathrm{value of e.weight where e has maximum value of weight from all elements}$
\STATE $\mathrm{minWeight} \leftarrow \mathrm{value of e.weight where e has minimum value of weight from all elements}$
\STATE $\mathrm{maxDrawValue} \leftarrow \mathrm{value of element maximum size in visualization}$
\STATE $\mathrm{minDrawValue} \leftarrow \mathrm{ value of element minimum size in visualization}$
\Function{CountDrawValue}{elementWeight}
\IF maxWeight = minWeight
\RETURN $\frac{maxWeight + minWeight}{2}$
\EndFunction
\end{algorithmic}
오류 메시지가 나타납니다
! Undefined control sequence.
l.631 \Function
{CountDrawValue}{elementWeight}
?
답변1
아마도 당신은 다음과 같은 것을 찾고 있을 것입니다:
\documentclass{article}
\usepackage{algpseudocode,amsmath}
\newcommand{\var}{\texttt}
\newcommand{\assign}{\leftarrow}
\newcommand{\multilinestate}[1]{%
\parbox[t]{\linewidth}{\raggedright\hangindent=\algorithmicindent\hangafter=1
\strut#1\strut}}
\begin{document}
\begin{algorithmic}
\State \multilinestate{$\var{maxWeight} \assign{}$value of \var{e.weight} where~\var{e} has maximum value of weight from all elements}
\State \multilinestate{$\var{minWeight} \assign{}$value of \var{e.weight} where~\var{e} has minimum value of weight from all elements}
\State $\var{maxDrawValue} \assign{}$value of element maximum size in visualization
\State $\var{minDrawValue} \assign{}$value of element minimum size in visualization
\Function{CountDrawValue}{\var{elementWeight}}
\If{$\var{maxWeight} = \var{minWeight}$}
\State\Return $(\var{maxWeight} + \var{minWeight}) / 2$
\EndIf
\EndFunction
\end{algorithmic}
\end{document}
\Function
에 의해 공급됩니다algpseudocode
\STATE
을(를) 통해서만 사용할 수 있습니다 algcompatible
.algorithmic
. 귀하의 입력을 algpseudocode
.