6
$\begingroup$

We are aware that a user may utilize 'ColorFunction' gradients such as 'Rainbow' for plotting. How can we implement a gradient style as a rainbow spectrum to multiple cells in which there are multiple lines of commands, as shown in the image below?

enter image description here

I am aware of one method: using "Background Color" manually for each cell. However, if the number of cells is substantial, this procedure would be lengthy. How can this process be automatically implemented?

$\endgroup$

1 Answer 1

6
$\begingroup$

Is this what you are after?


colors = ColorData["Rainbow"] /@ Range[0, 1, .1];

With[{colors = colors, length = Length@colors},
 
 SetOptions[
  EvaluationNotebook[],
  StyleDefinitions -> Notebook[{
     Cell[StyleData[StyleDefinitions -> "Default.nb"]],
     Cell[StyleData["Input"],
      Background -> FEPrivate`Part[
        colors,
        FEPrivate`Mod[FrontEnd`CurrentValue[{"CounterValue", "Input"}], length, 1]
        ]
      ]
     }
    , StyleDefinitions -> "PrivateStylesheetFormatting.nb"
    ]
  ]
 
 
 
 ]

enter image description here

$\endgroup$
1
  • $\begingroup$ Wonderfull and excellent!!!! $\endgroup$
    – monfneg
    Jun 5, 2023 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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