12

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?

Vly
  • 388
  • 1
  • 8

1 Answers1

10
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

kglr
  • 394,356
  • 18
  • 477
  • 896
  • 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"], ...] ?

    – Vly Feb 13 '21 at 13:22
  • @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. – kglr Feb 13 '21 at 13:42
  • 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! – Vly Feb 13 '21 at 14:22
  • @Vly, my pleasure.Thank you for the accept. And welcome to mma.se. – kglr Feb 13 '21 at 14:24
  • @kglr My question is not above code, but about adjusting number of rows in Dataset. In the above table it is seen "rows 1-20 of 1309" In general,using Dataset, How can we adjust the number of rows that we can see in the table? For instance, can we make it "1-40" instead of "1-20" . Moreover, using Data set, How can we see all list in one single table? – gunes Mar 28 '21 at 08:39
  • 1