4
$\begingroup$

enter image description here

As shown in the table above, if the font of the cells in the first column and second row is bolded, or if the font of several cells is bolded, it is generally possible to add a Style ["", Bold] statement in a certain cell. However, adding a few cells separately can be cumbersome. Is there any other convenient method?

summaryGrid = 
 Transpose[{{"Function", "Domain", "All Zero points of Function", 
     "Zero points of Function in the Domain", 
     "Intersection point of Function", 
     "First-order Derivative Function f'[x]", 
     "All Zero points of f'[x]", "Zero points of f'[x] in the Domain",
      "Intersection point of f'[x]", "Increasing interval of f[x]", 
     "Decreasing interval of f[x]", "Global Maximum", 
     "Global Minimum", "Local Maximum", "Local Minimum"}, {f[x], 
     functionDomain, allZeroPoints, zeroPointsInDomain, 
     Style[intersectionPoints, FontColor -> Blue], 
     firstOrderDerivative, allZeroPointsDerivative, 
     zeroPointsDerivativeInDomain, 
     Style[intersectionPointsDerivative, FontColor -> Brown, Bold], 
     Style[increasingInterval, FontColor -> Red, Bold], 
     Style[decreasingInterval, FontColor -> Purple, Bold], 
     globalMaximum, globalMinimum, localMaximumValues, 
     localMinimumValues}}] // Grid[#, Dividers -> All, Frame -> All] &

For example, bold the font for the first column in three rows, five rows, seven rows, second column in two rows, and ten rows. Is there a convenient method above?

$\endgroup$
1
  • 3
    $\begingroup$ Have a look at the doc page for ItemStyle. $\endgroup$ Commented Feb 9 at 14:25

4 Answers 4

4
$\begingroup$
Clear["Global`*"];

grid = Transpose[{{"Function", "Domain", 
     "All Zero points of Function", 
     "Zero points of Function in the Domain", 
     "Intersection point of Function", 
     "First-order Derivative Function f'[x]", 
     "All Zero points of f'[x]", "Zero points of f'[x] in the Domain",
      "Intersection point of f'[x]", "Increasing interval of f[x]", 
     "Decreasing interval of f[x]", "Global Maximum", 
     "Global Minimum", "Local Maximum", "Local Minimum"}, {f[x], 
     functionDomain, allZeroPoints, zeroPointsInDomain, 
     intersectionPoints, firstOrderDerivative, 
     allZeroPointsDerivative, zeroPointsDerivativeInDomain, 
     intersectionPointsDerivative, increasingInterval, 
     decreasingInterval, globalMaximum, globalMinimum, 
     localMaximumValues, localMinimumValues}}];

Grid[grid, Dividers -> All
 , ItemSize -> {{25, 25}, {3, {1.8}}}
 , ItemStyle -> {None, None, {
    {5, 2} -> {Blue, Bold}
    , {9, 2} -> {Brown, Bold}
    , {10, 2} -> {Red, Bold}
    , {11, 2} -> {Purple, Bold}
    }
   }
 , Background -> {None, {Darker@Cyan
    , {White, LightBlue}}}
 ]

enter image description here

$\endgroup$
5
$\begingroup$

You can use ItemStyle option with Thread.

Add ItemStyle option to Grid.

ItemStyle -> {
              {{Automatic}}
             ,{{Automatic}}
             ,Thread[{{3, 1}, {5, 1}, {7, 1}, {2, 2}, {10, 2}} -> Bold]
             }

Hope this helps.

$\endgroup$
4
$\begingroup$

Do you mean this?

grid = 
    Transpose[{{"Function", "Domain", 
    "All Zero points of Function", 
    "Zero points of Function in the Domain", 
    "Intersection point of Function", 
    "First-order Derivative Function f'[x]", 
    "All Zero points of f'[x]", "Zero points of f'[x] in the Domain", 
    "Intersection point of f'[x]", "Increasing interval of f[x]", 
    "Decreasing interval of f[x]", "Global Maximum", "Global Minimum",
     "Local Maximum", "Local Minimum"}, {f[x], functionDomain, 
    allZeroPoints, zeroPointsInDomain, intersectionPoints, 
    firstOrderDerivative, allZeroPointsDerivative, 
    zeroPointsDerivativeInDomain, intersectionPointsDerivative, 
    increasingInterval, decreasingInterval, globalMaximum, 
    globalMinimum, localMaximumValues, localMinimumValues}}];

MapAt[Style[#, Bold] &, grid, {{3, 1}, {5, 1}, {7, 1}, {2, 2}, {10, 2}}] //
  Grid[#, Dividers -> All, Frame -> All] &

enter image description here

Or, as Sjoerd Smit commented,

Grid[grid,
 Dividers -> All,
 Frame -> All,
 ItemStyle ->
  {Automatic, Automatic,
   {{3, 1} -> Bold, {5, 1} -> Bold, {7, 1} -> Bold,
    {2, 2} -> Bold, {10, 2} -> Bold}}]

(* same result *)

Update

A semi-automatic approach motivated by Craig Carter's comment:

bold =
  {"All Zero points of Function", "Intersection point of Function", 
   "All Zero points of f'[x]", functionDomain, increasingInterval};

bpos = Thread[Position[grid, Alternatives @@ bold] -> Bold]

{{2, 2} -> Bold, {3, 1} -> Bold, {5, 1} -> Bold, {7, 1} -> Bold, {10, 2} -> Bold}

Grid[grid,
 Dividers -> All,
 Frame -> All,
 ItemStyle -> {Automatic, Automatic, bpos}]

(* same result *)

$\endgroup$
2
  • $\begingroup$ Another approach would be to wrap the target strings in Style: Style["my text",Bold] $\endgroup$ Commented Feb 9 at 16:39
  • $\begingroup$ Thanks, Craig, I updated the answer $\endgroup$
    – eldo
    Commented Feb 9 at 18:01
3
$\begingroup$

Using Dataset instead of Grid we get more flexible forms for styling cells including patterns to specify cells and functions to specify styles:

SeedRandom[1];
data = {StringRiffle[{#, #2}, " "], #3} & @@@ 
   ArrayReshape[RandomWord["Noun", 45], {15, 3}];
Grid[data, Dividers -> All]

enter image description here

Dataset[data,
 ItemStyle -> 
   {{3 | 5 | 8, 1} -> Bold,
    {2, 2} -> Bold, 
    {12, _} -> {Blue, Italic},
    {14} -> Directive[18, Bold, Italic, 
      FontVariations -> {"CapsType" -> "SmallCaps"}],
    {9} -> (FontSize -> 30 StringLength[#]/Max[StringLength @ #3] &), 
    {10} -> (FontOpacity -> StringLength[#]/Max[StringLength @ #3] &)}, 
 Background ->
   {{3 | 5 | 8, 1} -> LightGreen,
    {_, 2} -> (Append[.5] @
     ColorData[{"Rainbow", {1, Max[StringLength@#3[[All, 2]]]}}] @ 
     StringLength @ # &),
    {2 | 10, 2} -> LightRed}]

enter image description here

Note: A function f used at rhs of a rule takes three arguments (item value, position and input dataset) and returns a styling directive.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.