# How to modify default options of Dataset

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

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?

SetOptions[Dataset, HeaderBackground -> Black, HeaderStyle -> White,
ItemStyle -> Red];

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


ds[1]


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]}


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


ds[1]


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


• 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 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 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 at 14:22
• @Vly, my pleasure.Thank you for the accept. And welcome to mma.se. – kglr Feb 13 at 14:24
• @gunes, see the answers in this q/a – kglr Mar 28 at 8:58