我尝试了各种方法来打破一行函数,但没有成功。
从图中可以看出,我试图在函数参数的位置断线。有人可以看一下吗?
\begin{algorithm}[t]
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon instead
\SetKwFunction{proc}{XXXXXXXXX}
\SetKwProg{myproc}{XXXX}{}{}
\SetKwData{Kn}{XXXXXX}
\SetKwData{Dep}{XXX}
\SetKwData{Mt}{XXXXXXX}
\SetKwData{OMt}{XXXX}
\SetKwData{Con}{XXXXXXXX}
\SetKwData{OCon}{XXXXXXXXXXXXX}
\myproc{\proc{int \Dep, Knowledge \Kn}}{
\Begin{
\If{\Dep $< 3$} {
\Mt $\gets \mathit{XXXXXXXXXXXXXXX}(\Kn)$\;
\ForEach{\OMt in \Mt}{
\Con $\gets \mathit{XXXXXXXXX}(\OMt)$
\ForEach{\OCon in \Con}{
\Kn.$\mathit{XXXXXXXXXXX}(\OCon)$\;
\If{\Kn.$\mathit{XXXXX}()$} {
\Return{\Kn.$\mathit{XXXXXX}()$}
}
\Else{
\Return{XXXXXXXXX{$\Dep+1$, \Kn}}
}
}
}
}
}
}
多谢!!!!
答案1
我认为在这种情况下最好的方法是在参数之前发出一个新行,即替换该行
\Kn.$\mathit{XXXXXXXXXXX}(\OCon)$\;
和
\Kn.$\mathit{XXXXXXXXXXX}$\newline$(\OCon)$\;
梅威瑟:
\documentclass{article}
\usepackage[vlined]{algorithm2e}
\begin{document}
\begin{algorithm}[t]
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon instead
\SetKwFunction{proc}{XXXXXXXXX}
\SetKwProg{myproc}{XXXX}{}{}
\SetKwData{Kn}{XXXXXX}
\SetKwData{Dep}{XXX}
\SetKwData{Mt}{XXXXXXX}
\SetKwData{OMt}{XXXX}
\SetKwData{Con}{XXXXXXXX}
\SetKwData{OCon}{XXXXXXXXXXXXX}
\myproc{\proc{int \Dep, Knowledge \Kn}}{
\Begin{
\If{\Dep $< 3$} {
\Mt $\gets \mathit{XXXXXXXXXXXXXXX}(\Kn)$\;
\ForEach{\OMt in \Mt}{
\Con $\gets \mathit{XXXXXXXXX}(\OMt)$
\ForEach{\OCon in \Con}{
\Kn.$\mathit{XXXXXXXXXXX}$\newline$(\OCon)$\;
\If{\Kn.$\mathit{XXXXX}()$} {
\Return{\Kn.$\mathit{XXXXXX}()$}
}
\Else{
\Return{XXXXXXXXX{$\Dep+1$, \Kn}}
}
}
}
}
}
}
\end{algorithm}
\end{document}
输出:
如果需要,您可以添加一些水平空间来强调该行是从上面的行延续下来的:
\Kn.$\mathit{XXXXXXXXXXX}$\newline\hspace*{1.5em}$(\OCon)$\;
输出: