# Align text in loop println

Hi, I would like to align the column (v), how do I do it?

vect_mov = reshape(a,3,nno)' # matrix 3x4

for i = 1:nno

u = (round(1000*vect_mov[i,1], digits = 3))
v = (round(1000*vect_mov[i,2], digits = 3))

println("Node $i: u =$u   v = $v ") end One way is to use @printf the good old C style method: using Printf vect_mov = rand(3,4); for i = 1:3 @printf("Node %d: u = %7.3f v = %7.3f\n", i, round(1000*vect_mov[i,1], digits = 3), 1000*vect_mov[i,2]) end  which gives Node 1: u = 860.360 v = 182.717 Node 2: u = 301.294 v = 138.291 Node 3: u = 178.381 v = 210.087  5 Likes It’s wonderful, thanks Fyi, an alternative without Printf, just for fun: vect_mov = rand((0.0,2.097, 7.09, 13.1291, -10.161), 3, 4) for i = 1:3 u, v = round.((vect_mov[i,1],vect_mov[i,2]), digits=3) is = rpad.(string.(i), 2) us, vs = rpad.(string.((u,v)),8) println("Node$is: u = $us, v =$vs")
end

Node 1 : u = 13.129  , v = 2.097
Node 2 : u = 0.0     , v = 0.0
Node 3 : u = -10.161 , v = -10.161

1 Like