
Você poderia me ajudar, por favor, como posso escrever um pedaço de pseudocódigo com função em látex?
\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}
Recebo mensagem de erro
! Undefined control sequence.
l.631 \Function
{CountDrawValue}{elementWeight}
?
Responder1
Talvez você esteja atrás de algo parecido com isto:
\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
é fornecido poralgpseudocode
, enquanto o uso de \STATE
está disponível apenas através algcompatible
oualgorithmic
. Converti sua entrada em algo totalmente compatível com algpseudocode
.