我正在写一篇双栏格式的论文,我正在使用该algorithmic
包来排版我的算法。我的一个 while 循环条件有点长,因此不适合该栏。
当我尝试将条件分成几行时,它没有正确缩进,如\WHILE{this is the first line which barely fits into the column \\ this is the second line
}。
我还尝试了以下方法:
\WHILE{this is the first line which barely fits into the column \\
\hskip\algorithmicindent this is the second line}
但是,它仅将条件的第二行缩进与循环体相同的行数WHILE
,因此需要与循环条件的第一行对齐。我该如何实现这一点?
MWE如下:
\documentclass[twocolumn]{article}
\usepackage{algorithmic}
\begin{document}
\begin{algorithmic}
\WHILE{There is an element which satisfies \\
\hskip\algorithmicindent properties which are long}
\STATE{while-body}
\ENDWHILE
\end{algorithmic}
\end{document}
答案1
以下 MWE 提供了\pushcode[<num>]
哪些缩进可以使您的代码从左边距<num>
缩进( )。默认(因为是可选的)是缩进。您还可以通过指定负数来“取消缩进”您的代码(请注意,这可能会将代码推入行号中)。\algorithmicindent
<num>
1
\documentclass{article}
\usepackage{algorithmic}% http://ctan.org/pkg/algorithmic
\newcommand{\pushcode}[1][1]{\hskip\dimexpr#1\algorithmicindent\relax}
\begin{document}
\begin{algorithmic}[1]
\WHILE{this is the first line which barely fits into the column \\
\pushcode[2] this is the second line}
\STATE here is some content
\ENDWHILE
\STATE here is some more content
\end{algorithmic}
\end{document}