Message Boards Message Boards

GROUPS:

Make table headings centered and column entries right justified?

Posted 1 month ago
285 Views
|
4 Replies
|
1 Total Likes
|

Consider the following code:

m = Table[i, {i, 0.10, 0.50, 0.02}]
    alpha0 = 1/m^2
    alpha1 = -(7*(1 - 4*m + 5*m^2))/(2*m^2 * (2 - 7*m + 7*m^2))
    beta0 = (10 - 28*m + 21*m^2)/( 2*(1 - m)^2 * (2 - 7*m + 7*m^2))
    beta1 = - (7*(2 - 6*m + 5*m^2))/(2*(1 - m)^2 * (2 - 7*m + 7*m^2))
    gamma = 105/(2*(2 - 7*m + 7*m^2))
    delta0 = (3 * (2 - 8*m + 7*m^2))/(4*
        m^2 *(1 - m)^3 * (2 - 7*m  + 7*m^2))
    delta1 = - (2 - 4*m  - 14*m^2 + 21*m^3) / (2*
        m^3 * (1 - m)^3 * (2 - 7*m + 7*m^2))
    delta2 = (7*(1 - 5*m + 5*m^2)) / (4*
        m^3 * (1 - m)^3 * (7*m^2 - 7*m + 2))
    NumberForm[
     TableForm[{m, alpha0, alpha1, beta0, beta1, gamma, delta0, delta1, 
       delta2}, TableDirections -> Row, TableAlignments -> Right, 
      TableHeadings -> {{"m", "alpha0", "alpha1", "beta0", "beta1", 
         "gamma", "delta0", "delta1", "delta2"}, None}, 
      TableAlignments -> Center], {9, 5}]
4 Replies

Kevin,

TableForm has limited control. I would suggest that you use Grid[] instead. You can control all alignment and dividers, etc. with Grid[]

Regards,

Neil

Posted 1 month ago

I'll give that a try. Many thanks!

Posted 1 month ago

Using Grid as Neil suggested:

data = {m, alpha0, alpha1, beta0, beta1, gamma, delta0, delta1, delta2};
headerRow = {"m", "alpha0", "alpha1", "beta0", "beta1", "gamma", "delta0", "delta1", "delta2"};
headerAlignment = Table[{1, i} -> Center, {i, Length[headerRow]}];
textGrid = data // Map[NumberForm[#, {9, 5}] &, #, {2}] & // Transpose // Prepend[headerRow];

Grid[textGrid, Frame -> All, ItemStyle -> {{}, {1 -> Bold}}, 
 Background -> {{}, {LightYellow, None}}, 
 Alignment -> {Right, Automatic, headerAlignment}]

enter image description here

Posted 1 month ago

Just what the doctor ordered! Now need to study this. Many thanks.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract