0

I have a double page document and I wish to add an algorithm at a certain point. But if I just include the algorithm (of the algorithm2e package) then the text gets really bad since many lines of the algorithm break the column.

So I have my algorithm some thing like

\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}

And I want to 'wrap' that with an adjustbox in order to make it fit. Like

\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}

The problem is that when I try to do it like that, I get a compilation error. This does not work. Are there any workarounds for this?

I also don't wish for \tcp*[h] comments to break is this possible? To shrink them in one line?

Thanks in advance.

11
  • Please prepare a complete minimal working example and add it to your question. With such an example file, others can reproduce the output you get. – leandriis Nov 23 '20 at 18:16
  • What exactly does "double page" and "break the column" refer to here? Do you have a twocolumn layout (two columns of text per page)? – leandriis Nov 23 '20 at 18:17
  • Yes a two column layout. Two columns of text per page @leandriis . Take the MCVE that I edited if it suits you – Broxigar Nov 23 '20 at 18:27
  • @Broxigar: Note that width-\textwidth is not correct; you're probably interested in width=\textwidth. – Werner Nov 23 '20 at 18:33
  • Please prepare a complete minimal working example (MWE) starting with \documentclass and ending with \end{document} that shows what exactly you do. By default, overly wide lines in an algorithm2e algorithm environment should be broken into multiple lines avoiding an overlap with the adjacent column's text. If that's not the case in your document, this must be caused by something you did not show yet. – leandriis Nov 23 '20 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.