# Arrange Grid of Table elements horizontally [closed]

I have a Table consisting of an independent variable and two functions. I want to output it like this:

x   1    2    3    4    5  ...
f f(1) f(2) f(3) f(4) f(5) ...
g g(1) g(2) g(3) g(4) g(5) ...


but doing

Grid[Table[...]]


arranges the values vertically. Any way around this?

This is a canonical way of getting what you want:

data = Table[i[j], {i, {f, g}}, {j, 1, 5}];
data,


\begin{array}{c|ccccc} \text{} & 1 & 2 & 3 & 4 & 5 \\ \hline f & f(1) & f(2) & f(3) & f(4) & f(5) \\ g & g(1) & g(2) & g(3) & g(4) & g(5) \\ \end{array}

Sorry I can't easily get the "x" in the top. If that's important, the other answer is better.

Although there are probably slightly more elegant answers, the following works:

gridDraw[N_] :=
Module[{aRange = Range[N], bRange = Range[N], cRange}, PrependTo[bRange, ""];
Grid[{bRange, Flatten[{f, f /@ aRange}], Flatten[{g, g /@ aRange}]},
Frame -> All]]


By just calling:

gridDraw[5]


You get exactly the same as above (apart from the square parentheses):

\begin{array}{cccccc} \text{} & 1 & 2 & 3 & 4 & 5 \\ f & f(1) & f(2) & f(3) & f(4) & f(5) \\ g & g(1) & g(2) & g(3) & g(4) & g(5) \\ \end{array}

Hope that helps.