This is a followup to:
Carl Woll gave a great answer there: change the "Graphics"
style of the current notebook's stylesheet. This is simple to do and indeed affects the style in all GraphicsBox
es.
Unfortunately, the style change does not stick when we export a legended figure to PDF.
Question: How can we work around this problem and preserve the new style even when exporting to PDF?
Demonstration:
We set the "Graphics"
style for all style environments:
SetOptions[EvaluationNotebook[],
StyleDefinitions -> Notebook[{
Cell[StyleData[StyleDefinitions -> "Default.nb"]],
Cell[StyleData["Graphics", All], FontFamily -> "Times"]
},
StyleDefinitions -> "PrivateStylesheetFormatting.nb"]
]
Additionally, we change the printing style environment to "Working"
. Otherwise Export
would use the "Printout"
environment for labelled plots, which would downscale everything.
SetOptions[$FrontEndSession, PrintingStyleEnvironment -> "Working"]
Let's try exporting these two plots:
plot1 = DensityPlot[x, {x, -1, 1}, {y, -1, 1}, PlotLabel -> "Plot 1"]
plot2 = DensityPlot[x, {x, -1, 1}, {y, -1, 1}, PlotLabel -> "Plot 2", PlotLegends -> Automatic]
Both use the Times font when displayed in the notebook, but plot2
will revert to the default font when exported to PDF:
Note: To be more precise, the problem appears when we export something that is not represented as a GraphicsBox
. This is the case with Legended
expressions when the legend is placed outside of the plot frame. Row[{plot1}]
also doesn't export correctly.