我需要将评论向右移动。基本上,在下面的图片中
该注释分散了伪代码的注意力,因此,我希望得到下面的图片
如何将注释移到右侧?这是我的代码
\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{algorithm,algpseudocode,float}
%-----------
\makeatletter
\newenvironment{breakablealgorithm}
{% \begin{breakablealgorithm}
\begin{center}
\refstepcounter{algorithm}% New algorithm
\hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
\renewcommand{\caption}[2][\relax]{% Make a new \caption
{\raggedright\textbf{\ALG@name~\thealgorithm} ##2\par}%
\ifx\relax##1\relax % #1 is \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
\else % #1 is not \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
\fi
\kern2pt\hrule\kern2pt
}
}{% \end{breakablealgorithm}
\kern2pt\hrule\relax% \@fs@post for \@fs@ruled
\end{center}
}
\makeatother
\begin{document}
\begin{breakablealgorithm}
\caption{PPPPPPPPPPPPP}
\begin{algorithmic}[1]
\makeatletter\setcounter{ALG@line}{0}\makeatother
\If { $\phi < 10^\circ$}
\State{$A = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$} \Comment{ where \textbf{a} is aaaaaaaaaa constant.}
\Else
\State{$B = bbbbbbbbb$ }
\EndIf
\end{algorithmic}
\end{breakablealgorithm}
\end{document}
答案1
您可以使用\parbox
(\raggedright
如果太窄则带有文本):
\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{algorithm,algpseudocode,float}
%-----------
\makeatletter
\newenvironment{breakablealgorithm}
{% \begin{breakablealgorithm}
\begin{center}
\refstepcounter{algorithm}% New algorithm
\hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
\renewcommand{\caption}[2][\relax]{% Make a new \caption
{\raggedright\textbf{\ALG@name~\thealgorithm} ##2\par}%
\ifx\relax##1\relax % #1 is \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
\else % #1 is not \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
\fi
\kern2pt\hrule\kern2pt
}
}{% \end{breakablealgorithm}
\kern2pt\hrule\relax% \@fs@post for \@fs@ruled
\end{center}
}
\makeatother
\begin{document}
\begin{breakablealgorithm}
\caption{PPPPPPPPPPPPP}
\begin{algorithmic}[1]
\makeatletter\setcounter{ALG@line}{0}\makeatother
\If { $\phi < 10^\circ$}
\State{$A = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$} \Comment{\parbox[t]{4cm}{\raggedright where \textbf{a} is some unknown constant.}}
\Else
\State{$B = bbbbbbbbb$ }
\EndIf
\end{algorithmic}
\end{breakablealgorithm}
\end{document}