如何在算法中应用调整框(2e)

如何在算法中应用调整框(2e)

我有一份双页文档,我想在某个位置添加一个算法。但如果我只包含算法(algorithm2e 包的算法),那么文本会变得很糟糕,因为算法的许多行会破坏列。

所以我的算法是这样的

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts

\usepackage{lipsum}

\usepackage[ruled,vlined,linesnumbered,lined,commentsnumbered]{algorithm2e}
\newsavebox{\tempbox}
\let\oldnl\nl% Store \nl in \oldnl
\newcommand{\nonl}{\renewcommand{\nl}{\let\nl\oldnl}}% Remove line number for one line
\begin{document}

    \title{For the Horde!}
    
    \author
    { 
        \IEEEauthorblockN{  Broxigar the Ax \IEEEauthorrefmark{2}}
        {
            \begin{tabular}{cc}
                \begin{tabular}{@{}c@{}}
                \IEEEauthorrefmark{2}
                    Orgrimmar, Azeroth
                \end{tabular}  
            \end{tabular}
        }
    }
    \maketitle
    
    
    \begin{abstract}
        \lipsum[1]
    \end{abstract}
    
    \section{Erroneous Algorithm}
    
    \begin{adjustbox}{width=0.5\textwidth} % half the pagewidth
         \begin{algorithm}[tbh]
              \SetAlgoLined
              \SetKwFunction{INT}{Intersection}
              \SetKwFunction{UN}{Union}
              \SetKwFunction{MAX}{Maximize}
    
              \SetKwInOut{Input}{input}
              \SetKwInOut{Output}{output}
    
              \Input{Tree integer numbers, one prime number and one banana}
              \Output{The circumference of our planet}
    
              \BlankLine
   
              \For{$i \leftarrow 0$ \KwTo $100,000,000$}
              {
             \tcp*[h]{Maximize the minimized value twice}
             \MAX{this\_is\_going\_to\_break\_the\_column\_width\_for\_sure,tw}\;
             }
        \end{algorithm}
    \end{adjustbox}

\end{document}

我想用调整框“包裹”它,以使其适合。就像

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts


\usepackage{lipsum}

\usepackage[ruled,vlined,linesnumbered,lined,commentsnumbered]{algorithm2e}
\newsavebox{\tempbox}
\let\oldnl\nl% Store \nl in \oldnl
\newcommand{\nonl}{\renewcommand{\nl}{\let\nl\oldnl}}% Remove line number for one line
\begin{document}

    \title{For the Horde!}
    
    \author
    { 
        \IEEEauthorblockN{  Broxigar the Ax \IEEEauthorrefmark{2}}
        {
            \begin{tabular}{cc}
                \begin{tabular}{@{}c@{}}
                \IEEEauthorrefmark{2}
                    Orgrimmar, Azeroth
                \end{tabular}  
            \end{tabular}
        }
    }
    \maketitle
    
    
    \begin{abstract}
        \lipsum[1]
    \end{abstract}
    
    \section{Erroneous Algorithm}
    
    \begin{algorithm}[tbh]
    \SetAlgoLined
    \SetKwFunction{INT}{Intersection}
    \SetKwFunction{UN}{Union}
    \SetKwFunction{MAX}{Maximize}
    
    \SetKwInOut{Input}{input}
    \SetKwInOut{Output}{output}
    
    \Input{Tree integer numbers, one prime number and one banana}
    \Output{The circumference of our planet}
    
    \BlankLine
    
        
    \For{$i \leftarrow 0$ \KwTo $100,000,000$}
    {
        \tcp*[h]{Maximize the minimized value twice}
        \MAX{this\_is\_going\_to\_break\_the\_column\_width\_for\_sure,tw}\;
    }
    \end{algorithm}
    
\end{document}
\end{adjustbox}

问题是,当我尝试这样做时,会出现编译错误。这不起作用。有没有什么解决方法?

我也不希望 \tcp*[h] 注释中断,这可能吗?将它们缩减为一行?

提前致谢。

相关内容