tuna / thuthesis

LaTeX Thesis Template for Tsinghua University
https://www.ctan.org/pkg/thuthesis
LaTeX Project Public License v1.3c
4.58k stars 1.08k forks source link

算法流程中无法定义函数(\FUNCTION) #810

Closed Shao-Kui closed 2 years ago

Shao-Kui commented 2 years ago

编译环境

编译的系统:Overleaf TeX 发行版:TeX Live 2021 模板版本:v7.3.0 模板类型:doctor

描述问题

请问模板是否可以在算法流程中定义函数呢?下面的代码在编译后,提示在\FUNCTION{}{}处报了“Undefined control sequence”。只要把\FUNCTION和\ENDFUNCTION注释掉,就能正常编译通过并显示PDF。我尝试了\Function、\FUNCTION、\PROCEDURE、\Procedure等类似的指令,都没有办法通过编译...

复现上述问题的代码:

\begin{algorithm}
    \caption{Geometric Arranging} 
    \label{alg:ra}
    \small
    \begin{algorithmic}
        \REQUIRE
        Polygon of room's inner side $P_{r} $
        List of rectangles of coherent groups with height $A_{rec}$
        List of rectangles of windows and doors
        \ENSURE Transformations of rectangles $T_{rec}$

        \FUNCTION{InsertRectangle}{$A$}
        \STATE Let $T$ be array of transformations
        \FOR{$edge \in P_{r}$ and $p \in $existing polygons}
        \STATE Push heuristic transformation of $edge$ or $p$ to $T$
        \ENDFOR

        \FOR{$t \in T$}
        \IF{CheckOK(ApplyTransform($A$,$t$))}
            \STATE return $t$;
        \ENDIF
        \ENDFOR

        \STATE Clear $T$
        \FOR{$n=1 \to max\,sampling\,density$}
        \FOR{$edge \in P_{r}$}
        \STATE Push $2^n*len(edge)$ random transformations on $edge$ to $T$ 
        \ENDFOR

        \STATE Shuffle $T$

        \FOR{$t \in T$}
        \IF{CheckOK(ApplyTransform($A$,$t$))}
            \STATE return $t$;
        \ENDIF
        \ENDFOR
        \STATE Clear $T$
        \ENDFOR
        \STATE return None;

        \ENDFUNCTION

        \FOR{$a \in A_{rec}$}
        \STATE Push InsertRectangle($a$) to $T_{rec}$;
        \ENDFOR
    \end{algorithmic}
\end{algorithm}
zepinglee commented 2 years ago

algorithms 宏包似乎没有,algorithem2e 宏包提供了 \Fn