[英]Indentation in latex algorithmic
如何在乳膠中的算法(算法)中縮進行?
我希望能夠寫下列內容:
\begin{algorithm}[H]
\caption{My Awesome Program} \label{awesome-algorithm}
\begin{algorithmic}[1]
\FOR { $i=0$ to $logn$ }
\STATE Step A:
% would like the indent the next lines...
\STATE do something
\STATE do another thing
\STATE Step B
\ENDFOR
\end{algorithmic}
\end{algorithm}
怎么可能縮進這些線? 我一直試圖通過谷歌搜索找到答案,但沒有成功。 我希望你們能幫助我。 謝謝。
我目前正在使用以下內容進行縮進:
\STATE \ \ \ \ do something
這似乎是完全錯誤的。 但是有效。
試試這個:
\STATE\hspace{\algorithmicindent} do something
\STATE\hspace{\algorithmicindent} do another thing
它應該更好地工作,因為它使用當前縮進值進行縮進。
編輯 :使用Charles的建議,您可以定義一個新命令, \\INDSTATE
:
\newcommand{\INDSTATE}[1][1]{\STATE\hspace{#1\algorithmicindent}}
然后在需要縮進時使用它。 默認情況下, \\INDSTATE
按一個級別縮進,但您可以更改它:
\INDSTATE do something % What you want
\INDSTATE[2] do something % Indent by twice the amount
我建議你不要這樣縮進。 該軟件包旨在以標准方式格式化偽代碼,以使您的讀者更容易。
你正試圖打破這個標准。 嘗試重寫代碼以符合讀者的期望會好得多。
無論如何,為什么要標記步驟A和B? 每個陳述都應該是它自己的一步。 您似乎正在添加額外的結構,實際上使代碼的可讀性降低。 您可以通過評論獲得相同的效果嗎? 把“做某事”和“做另一件事”合並成一個陳述怎么樣?
我無法讓Alok工作,所以我寫了這個:
% Put in preamable:
\usepackage{forloop}
\newcounter{ct}
\newcommand{\markdent}[1]{\forloop{ct}{0}{\value{ct} < #1}{\hspace{\algorithmicindent}}}
\newcommand{\markcomment}[1]{\Statex\markdent{#1}}
然后,在縮進級別3處輸入“這是我的評論”:
\markcomment{3}{"This is my comment"}
編輯:我使用algoritmicx(因此\\州而不是\\ STATE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.