break an long line in an algorithm
Something like this, with adjustable indentation. The solution defines a new command called \myindent
constituted with \newline
and \makebox{#1}{}
, taking one argument for length.
Code
\documentclass{article}
\usepackage{amsmath}
\usepackage[boxed,vlined,linesnumbered,noresetcount]{algorithm2e}
\newcommand{\myindent}[1]{
\newline\makebox[#1cm]{}
}
\begin{document}
\begin{algorithm}[tp]
out := foo(x$\rightarrow$child[which]
\myindent{0.3},$\langle$1,0,0,old$\rangle$
\myindent{0.3},$\langle$0,0,0,new$\rangle$)\;
\end{algorithm}
\end{document}
Setting the breakable portion in a \parbox
of sufficient width allows you to break it at will as well as properly align the content:
\documentclass{article}
\usepackage{mathtools}
\usepackage[boxed,vlined,linesnumbered,noresetcount]{algorithm2e}
\begin{document}
\begin{algorithm}[tp]
\texttt{out} $\vcentcolon=$ \textsc{foo}($\texttt{x} \rightarrow \texttt{child[which]}$, $\langle 1,0,0,\texttt{old} \rangle$, $\langle 0,0,0,\texttt{new} \rangle$\;
\texttt{out} $\vcentcolon=$ \textsc{foo}(\parbox[t]{.6\linewidth}{%
$\texttt{x} \rightarrow \texttt{child[which]}$, \\
$\langle 1,0,0,\texttt{old} \rangle$, \\
$\langle 0,0,0,\texttt{new} \rangle$)\;}
\end{algorithm}
\end{document}
You can define a new command \WRP
like that:
\newcommand{\WRP}{\par\qquad\(\hookrightarrow\)\enspace}
...
\begin{document}
...
\begin{algorithm}[H]
\begin{algorithmic}[1]
...
\STATE This line\WRP needs to be wrapped
Syntax: \newcommand{\name}[args]{definition}
Note: Make sure the command isn't already defined.
Result: