1

I tried various ways to break a line of function but did not succeed.

enter image description here

As you can see from the image, I was trying to break the line at the position of a function parameter. Can anybody please take a look?

\begin{algorithm}[t]
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon instead

\SetKwFunction{proc}{XXXXXXXXX}  
\SetKwProg{myproc}{XXXX}{}{}
\SetKwData{Kn}{XXXXXX}
\SetKwData{Dep}{XXX}
\SetKwData{Mt}{XXXXXXX}
\SetKwData{OMt}{XXXX}
\SetKwData{Con}{XXXXXXXX}
\SetKwData{OCon}{XXXXXXXXXXXXX}

\myproc{\proc{int \Dep,  Knowledge \Kn}}{ 
    \Begin{
         \If{\Dep $< 3$} {
                \Mt $\gets \mathit{XXXXXXXXXXXXXXX}(\Kn)$\;

            \ForEach{\OMt in \Mt}{
                    \Con $\gets \mathit{XXXXXXXXX}(\OMt)$

                \ForEach{\OCon in \Con}{
                        \Kn.$\mathit{XXXXXXXXXXX}(\OCon)$\;
                    \If{\Kn.$\mathit{XXXXX}()$} {
                            \Return{\Kn.$\mathit{XXXXXX}()$}
                         }
                    \Else{
                             \Return{XXXXXXXXX{$\Dep+1$, \Kn}}
                     }                              
                }
                 }
              }     
     }
}

Thanks a lot!!!!

2

I think in this case the best method is to issue a new line just before the parameter, that is substitute the line

                    \Kn.$\mathit{XXXXXXXXXXX}(\OCon)$\;

with

                    \Kn.$\mathit{XXXXXXXXXXX}$\newline$(\OCon)$\;

MWE:

\documentclass{article}

\usepackage[vlined]{algorithm2e}

\begin{document}

\begin{algorithm}[t]
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon instead

\SetKwFunction{proc}{XXXXXXXXX}
\SetKwProg{myproc}{XXXX}{}{}
\SetKwData{Kn}{XXXXXX}
\SetKwData{Dep}{XXX}
\SetKwData{Mt}{XXXXXXX}
\SetKwData{OMt}{XXXX}
\SetKwData{Con}{XXXXXXXX}
\SetKwData{OCon}{XXXXXXXXXXXXX}

\myproc{\proc{int \Dep,  Knowledge \Kn}}{
    \Begin{
         \If{\Dep $< 3$} {
                \Mt $\gets \mathit{XXXXXXXXXXXXXXX}(\Kn)$\;

            \ForEach{\OMt in \Mt}{
                    \Con $\gets \mathit{XXXXXXXXX}(\OMt)$

                \ForEach{\OCon in \Con}{
                        \Kn.$\mathit{XXXXXXXXXXX}$\newline$(\OCon)$\;
                    \If{\Kn.$\mathit{XXXXX}()$} {
                            \Return{\Kn.$\mathit{XXXXXX}()$}
                         }
                    \Else{
                             \Return{XXXXXXXXX{$\Dep+1$, \Kn}}
                     }
                }
                 }
              }
     }
}
\end{algorithm}

\end{document} 

Output:

enter image description here

If you want, you can some horizontal space to emphasise the fact that the line is continuing from the above one:

                    \Kn.$\mathit{XXXXXXXXXXX}$\newline\hspace*{1.5em}$(\OCon)$\;

Output:

enter image description here

1
  • @user1935724 you're welcome. Mar 30 '14 at 7:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.