MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Q: How do I format text within a cell of GridBox[]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64694] Re: Q: How do I format text within a cell of GridBox[]?
  • From: bghiggins at ucdavis.edu
  • Date: Tue, 28 Feb 2006 01:49:25 -0500 (EST)
  • References: <dtrvfb$ltl$1@smc.vnet.net><dtu2ln$eur$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Terry,

Here is a modification of David's suggestion that allows the user to
determine the size of the heading fragment on each line. It makes use
of RegularExpressions( need Version 5.1 or later )

We need two auxillary functions. The first function called myNewLineLoc
places a new line locator (\n) in front of any word after the first in
a heading that has n or more word characters(digits,letters,or _)

myNewLineLoc[str_String,
    n_Integer] := StringReplace[str, RegularExpression["((?!^)\\b\\w{"
<> \
ToString[n] <> "})"] :> "\n" <> "$1"]

The second function called setColumnWidths determines the size of the
largest heading fragment using the same rule as above for splitting up
the header

SetColumnWidths[str_String, n_Integer] := Max[Map[StringLength[#] &, \
StringSplit[StringReplace[str,  RegularExpression["((?!^)\\b\\w{" <>
      ToString[n] <> "})"] :> "\n" <> "$1"], "\n"]]]

Finally we call this functions in a PrintHeading function

PrintHeading[{str__String}, {colWidths__}] := \
Print[DisplayForm[GridBox[{Map[Cell[myNewLineLoc[#[[1]], #[[2]]], \
TextAlignment -> Center] &, Transpose[{{str}, {colWidths}}]]},
        	 ColumnSpacings -> 0.8, ColumnWidths ->
                Map[SetColumnWidths[#[[1]], #[[
                  2]]] &, Transpose[{{str}, {colWidths}}]]]]]

The following shows how the options work:

PrintHeading[{"Time", "Number of Times Parameters Changes Directions",
 "Error"}, {4, 6, 5}]

PrintHeading[{"Time", "Number of Times Parameters Changes Directions",
 "Error"}, {4, 8, 5}]

The one limitation is that the size of the columnwidth is based on the
number of characters in the largest heading fragment, which does not
map one-to-one on how Mathematica defines a width of a column.

Hope this helps,

Cheers

Brian


  • Prev by Date: Re: Re: How if I want to assume that -------
  • Next by Date: pictures of mathematics on a non-white background
  • Previous by thread: Re: Q: How do I format text within a cell of GridBox[]?
  • Next by thread: FindRoot and NDSolve