如何使代码块在Overleaf中换行?

问题描述 投票:0回答:1

我没有让我的代码块换行,如图after compiled

这是我的代码

\makeatletter
\newif\if@restonecol
\makeatother
\let\algorithm\relax
\let\endalgorithm\relax
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}%[ruled,vlined]{
\usepackage{algpseudocode}
\renewcommand{\algorithmicrequire}{\textbf{Input:}} 
\renewcommand{\algorithmicensure}{\textbf{Output:}} 

\begin{document}

\begin{algorithm}

\caption{trace column}  
\LinesNumbered  
\KwIn{
$v$:当前访问的节点\newline
$c$:当前访问节点所要溯源的列
}
\KwOut{
$S$ :遍历所找到的根节点的集合
}  
\textbf{Initialize} $S=\emptyset$ \;
\If{$v$ instanceof DataSourceNode}{
$n$.used=false\;
$n$.id=$v$.id\;
$n$.column=position of $c$ in $v$\;
$S=S\cup \{n\}$\;
}
\ElseIf{node instanceof JoinTreeNode}{
prenode[0]=node.input1\;
prenode[1]=node.input2\;
\For{i=0;i<2;i++}{
\If{$c$ is from prenode[i]}{
$S=S\cup trace$(prenode[i],position of $c$ in prenode[i])\;
\If{position of $c$ in prenode[i]=position of key in prenode[i]}{
$S=S\cup trace$(prenode[1-i],position of $c$ in prenode[1-i])\;
break\;
}
break\;
}
}
}
return $S$\newline
\end{algorithm} 

\begin{algorithm}
\caption{trace column22}  
....as the same code block....
\end{algorithm} 

\end{document}

我试图插入\newline\par,它没有用。还是我可以创建一个新文件并从2开始对算法块编号?

顺便说一下,如何在Overleaf中格式化代码?

latex
1个回答
0
投票

通过使用\ hfil,您将在算法结束后立即添加新行。

如果要在算法结束后立即在新页面中添加文本。然后您将使用\ break。

© www.soinside.com 2019 - 2024. All rights reserved.