Message Boards Message Boards

0
|
3997 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Make table headings centered and column entries right justified?

Posted 5 years ago

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}]
POSTED BY: Kevin Ulmer
4 Replies
Posted 5 years ago

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

POSTED BY: Kevin Ulmer
Posted 5 years 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 BY: Rohit Namjoshi
Posted 5 years ago

I'll give that a try. Many thanks!

POSTED BY: Kevin Ulmer

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 BY: Neil Singer
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