10
$\begingroup$

I try to make a dark stylesheet based on the ReverseColor theme. However, dataset headers are barely readable.

enter image description here

This question is related to others such as Question 1 and Question 2. But no solution has been found yet.

It seems that the new options for Dataset called HeaderStyle/HeaderBackground introduced in Version 12.1 might help, since it is now possible to modify headers:

ds = Dataset[{<|"a" -> 1, "b" -> 3|>,<|"a" -> 2, "b" -> 4|>}, HeaderStyle -> White, HeaderBackground -> Black]

However, any small change in the dataset restores the default settings:

ds[All, ;; 2]

I tried to modify the default values of HeaderStyle (None) and HeaderBackground (Automatic) by typing:

SetOptions[Dataset,HeaderBackground->Black,HeaderStyle->White]

Typing Options[Dataset] indicates that it changes the default values of these options but does not seem to apply since, for example, headers of:

Dataset[{<|"a"->3,"b"->4|>}]

and:

ds[All,;;2]

have the default format.

Any idea to modify the default layout of dataset headers from a stylesheet or at least for an entire notebook?

$\endgroup$
0
9
$\begingroup$
SetOptions[Dataset, HeaderBackground -> Black, HeaderStyle -> White, 
  ItemStyle -> Red];

ds = Dataset[{<|"a" -> 1, "b" -> 3|>, <|"a" -> 2, "b" -> 4|>}]

enter image description here

ds[1]

enter image description here

A cumbersome way to inject the options is to wrap dataset objects with Dataset[#, Options[Dataset]]&:

{Dataset[#,Options[Dataset]]& @ ds, Dataset[#,Options[Dataset]]& @ ds[1]}

enter image description here

A more convenient work-around is to use$PrePrint to inject the options into objects with head Dataset:

$PrePrint = If[Head[#] === Dataset, Dataset[#, Options[Dataset]], #] &;

ds

enter image description here

ds[1]

enter image description here

titanic = ExampleData[{"Dataset", "Titanic"}]  

enter image description here

$\endgroup$
6
  • $\begingroup$ The $Preprint solution is exactly what I missed to modify the formatting of my current Notebook. Many thanks @kglr ! The first solution seems a bit less useful since typing for example ds[2] removes the formatting. But can this $PrePrint solution be introduced in the stylesheet definition, with something like Cell[StyleData["Dataset"], ...] ? $\endgroup$
    – Vly
    Feb 13 at 13:22
  • $\begingroup$ @Vly, I don't know if/how it can be done via stylesheets. An easy way to avoid setting $PrePrint in every mma session is to add $PrePrint =... to the init.m file. $\endgroup$
    – kglr
    Feb 13 at 13:42
  • $\begingroup$ Thanks a lot @kglr! Of course, the best would have been to be able to include it in the stylesheet definition. But adding $PrePrint=... line to the init.m file perfectly extends the bevahior to all the notebooks. Also, now, I know the use of this init.m file. Thank you again! $\endgroup$
    – Vly
    Feb 13 at 14:22
  • $\begingroup$ @Vly, my pleasure.Thank you for the accept. And welcome to mma.se. $\endgroup$
    – kglr
    Feb 13 at 14:24
  • 1
    $\begingroup$ @gunes, see the answers in this q/a $\endgroup$
    – kglr
    Mar 28 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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