In the "algorithm" environment, when a function call spans multiple lines, I would like to have its arguments aligned, like so:
MyFunction(long_arg_name0,
long_arg_name1,
long_arg_name2);
How can I achieve this effect?
(second) EDIT: Here's a minimal example that fails to achieve the desired effect:
\documentclass{article}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}[t]
\begin{algorithmic}
\While{true}
\State MyLongWindedFunction(LongArgument0,\\ LongArgument1,\\ LongArgument2,\\ LongArgument3)
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}
When I stick the standard alignment marker &
between the arguments, I get the error message:
! Misplaced alignment tab character &.
l.10 \State MyLongWindedFunction(LongArgument0,&
\\ LongArgument1, &\\ Lon...
Best Answer
One possible solution would be to calculate the length of the string that preceeds the alignment point (in this case, the string
MyLongWindedFunction(
) and then use this length to add the necessary horizontal space:To answer the EDIT in the original question: simply add
\parindent
(the indentation used in the algorithm) to the length\mylen
: