将算法中的注释对齐到行尾

将算法中的注释对齐到行尾

这是我的算法:算法

可以看出,注释与行的右端对齐。我想将注释与同一行的末尾对齐。我希望注释出现在行结束的确切位置。以下是代码:

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{authblk}
\usepackage{textcomp}
\usepackage{mathtools}
\usepackage{filecontents}
\usepackage{microtype}
\usepackage{float}
\usepackage{adjustbox}
\usepackage{booktabs,makecell,tabularx}
\usepackage{url}
\usepackage{booktabs}
\usepackage{subfigure}

\begin{document}   
\begin{algorithm} 
            \caption{Bla Bla}
            \label{alg:ALG1}
            \begin{flushleft}
                \textbf{INPUT:} $N$ = no.   \\
                \textbf{OUTPUT:} Prediction of $W_{t_c}$    
            \end{flushleft}
            \begin{algorithmic}

            \\ BLALAAALALAdskjhfdsjk    \Comment{This is done as part}

            \end{algorithmic}
        \end{algorithm} 
\end{document}

答案1

可以 comment通过宏来改变\algrenewcommand{\algorithmiccomment}[1]{...}

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{authblk}
\usepackage{textcomp}
\usepackage{mathtools}
\usepackage{filecontents}
\usepackage{microtype}
\usepackage{float}
\usepackage{adjustbox}
\usepackage{booktabs,makecell,tabularx}
\usepackage{url}
\usepackage{booktabs}
\usepackage{subfigure}

\algrenewcommand{\algorithmiccomment}[1]{\hspace{1em}$\triangleright$ #1}

\begin{document}   
\begin{algorithm} 
            \caption{Bla Bla}
            \label{alg:ALG1}
            \begin{flushleft}
                \textbf{INPUT:} $N$ = no.   \\
                \textbf{OUTPUT:} Prediction of $W_{t_c}$    
            \end{flushleft}
            \begin{algorithmic}

            \\ BLALAAALALAdskjhfdsjk    \Comment{This is done as part}

            \end{algorithmic}
        \end{algorithm} 
\end{document}

在此处输入图片描述

相关内容