AlignColumns := proc( txt, align :: { "left", "right", "centre" } := "centre" ) uses StringTools; # Get a list of lists of fields local A := map( Split, Split( txt ), "$" ); # Calculate the column width local width := 1 + max( map( L -> max( map( length, L ) ), A ) ); # Add spacing according to the requested type of alignment if align = "left" then local J := map( line -> map( PadRight, line, width ), A ) elif align = "right" then J := map( line -> map( PadLeft, line, width ), A ) else J := map( line -> map( Center, line, width ), A ) end if; # Join up the fields in each line. J := map( cat@op, J ); # Re-assemble the lines into a single string. Join( J, "\n" ) end proc: