算法中自定义字体超出页面右边距

算法中自定义字体超出页面右边距

我正在使用 latex 中的算法包编写算法。我已根据需要自定义了注释的字体样式。为此,我使用了 MWE 中定义\COMMENT\LONGCOMMENT给出的两个命令。但长注释超出了页面的右边距。有人可以提供解决方案吗?

\documentclass{article}

\usepackage{algorithmic}
\usepackage{algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\usepackage{eqparbox}
\renewcommand\algorithmiccomment[1]{\hfill \texttt{ \eqparbox{COMMENT}{// #1}}}
\newcommand\LONGCOMMENT[1]{\hfill \texttt{\begin{minipage}[t]{\eqboxwidth{COMMENT}}{// #1}\strut \end{minipage}}}
\usepackage{amssymb}
\begin{document}

\begin{algorithm}[H]                     
\caption{Reduction 1 and 2}          
\label{algo1}   
\algsetup{indent=3em}                        
\begin{algorithmic}[1]                   
    \REQUIRE The cluster-node incidence matrix $A$ and the number of nodes $m$ of the instance.
    \ENSURE The re-reduction edges of reduction:1 $E_{R_1}$, the set of reduced nodes $I_{R}$ and the reduced $A$. 
    \STATE $S = A^t \times A: S\in \mathbb{R}^{m\times m} $ \COMMENT{Scalar product}
    \STATE $E_{R_1}=\emptyset$
    \STATE $I_{R_1}=\emptyset$  \COMMENT{Index of the nodes to be removed by reduction 1} 
    \FORALL{$ i \in \lbrace 1,\ldots,m \rbrace $}
        \STATE $|\mathcal{C}(v_i)|= S_{i,i}$
        \STATE $Super\_set = \{j\mid S_{i,j}= |\mathcal{C}(v_i)| \}$ \COMMENT{The set of nodes $u$ such that  $\mathcal{C}(v_i) \subseteq \mathcal{C}(u)$}
        \IF{$Super\_set \neq \emptyset$} 
        \STATE {$u_i =$ First element of $Super\_set$}
        \STATE{Add the edge $(v,u_i)$  to the set $E_{R_1}$} 
        \STATE{Replace $S_{i,*}$ and $S_{*,i}$ by $[0,0, \ldots 0]_{1\times m}$ and $[0,0, \ldots 0]^t_{1\times m}$ respectively}
        \STATE{Replace $A_{*,i}$ by  $[0,0, \ldots 0]^t_{1\times n}$}
        \ENDIF
    \ENDFOR
    \STATE{Remove the columns $\{A_{*,j}\mid  A_{i,j}=0, \forall i\}$}
    \STATE{$I_{R}= \{1,2,\ldots m\} \setminus I_{R_1}$}
    \STATE{Remove the rows $\{A_{i,*}\mid  \sum\limits_{j=1}^{m} A_{i,j}<2 \}$} \LONGCOMMENT{These rows represent the clusters $\{ V_i\mid |V_i|<2\}$ i. e. this line apply the reduction:2}
\end{algorithmic}
\end{algorithm}
\end{document}

参见图

相关内容