# Mathematica for loop data how to export to table form in latex

I have created some data using the below code, want to export it latex in table form

 A=l(t^u)(x)^3; B=t^u(x + 2 l) ^3; C1=t^u(x+3l)^3; l = 3;
For [x = 0, x <= 2, x = x + 1, For [t = 0.01, t <= 0.03, t = t + 0.02,
Print [u = 0.25; x, " ", t, A, B, C1, u = 0.5;
" ", A, " ", B " ", C1]]]


I would not use For myself. But will leave that for you to change it if you want. I would just use Table.

But this is small modification to your code

ClearAll["Global*"]
A = l (t^u) (x)^3;
B = t^u (x + 2 l)^3;
C1 = t^u (x + 3 l)^3;
l = 3;
data = First@Last@Reap@For[x = 0, x <= 2, x = x + 1,
For[t = 0.01, t <= 0.03, t = t + 0.02,
Sow[{u = 0.25; x, " ", t, A, B, C1, u = 0.5; " ", A, " ", B " ",
C1}]
]
]


And now just do

 TeXForm[data] You can export the above and compile it using Latex to give can you suggest how to export in scientific form or restricting the data to fixed decimal places

I think it will best to do this at the source, i.e. when you generate the data. For example using Round[A,0.01] will round the value to 2 decimal points only.

ClearAll["Global*"]
A = l (t^u) (x)^3;
B = t^u (x + 2 l)^3;
C1 = t^u (x + 3 l)^3;
l = 3;
data = First@Last@Reap@For[x = 0, x <= 2, x = x + 1,
For[t = 0.01, t <= 0.03, t = t + 0.02,
Sow[{u = 0.25; x, t, Round[A, 0.01], Round[B, 0.01],
Round[C1, 0.01], u = 0.5; Round[A, 0.01], Round[B, 0.01],
Round[C1, 0.01]}]]]


Gives

TeXForm[data]

\left(
$$\begin{array}{cccccccc} 0 & 0.01 & 0. & 68.31 & 230.53 & 0. & 21.6 & 72.9 \\ 0 & 0.03 & 0. & 89.89 & 303.39 & 0. & 37.41 & 126.27 \\ 1 & 0.01 & 0.95 & 108.47 & 316.23 & 0.3 & 34.3 & 100. \\ 1 & 0.03 & 1.25 & 142.75 & 416.18 & 0.52 & 59.41 & 173.21 \\ 2 & 0.01 & 7.59 & 161.91 & 420.9 & 2.4 & 51.2 & 133.1 \\ 2 & 0.03 & 9.99 & 213.08 & 553.93 & 4.16 & 88.68 & 230.54 \\ \end{array}$$
\right)


Compiling There are many other Mathematica commands to Format numbers you can use also. You can also use NumberForm like this

n=NumberForm[1.23432,{2,3}]
(* 1.200 *)


And then export n to TeXForm. There is also AccountingForm and others. Check help for different command to format numbers.