Gray boxes around labels in exported image (PDF, JPEG,…)

From time to time, when I export plots with Mathematica, the labels have gray boxes as a rectangular background. I am using Mathematica 10.0.1 for Linux (gentoo) 64bit.

Consider this thing I again recently ran into:

b = 4;
n = 55;
datai = {#, PowerMod[b, #, n]} & /@ Range[1, 80];
p1 = ListPlot[datai, Frame -> True, Axes -> False, FrameLabel -> {"x", f(x)= 4^x (mod 55)"}, ImageSize -> 450, BaseStyle -> FontSize -> 17]
p2 = Grid[{{p1}}]
Export[NotebookDirectory[] <> "p1.pdf", p1];
Export[NotebookDirectory[] <> "p2.pdf", p2];


These are the results for p1 (top) and p2 (bottom):

I am not able to conclude in what situations I obtain thsese gray background boxes. "Luckily" I found out that it appears to be a workaround to wrap the plot into a Grid. It seems to me that all plot commands I use List(Line)Plot, (List)LogPlot, (List)Plot, (List)DensityPlot, (List)ContourPlot and maybe others are affected, regardless of the options. Also, it does not matter, whether I export as .pdf, .jpeg or .png (I guess also other formats are affected) or whether I use AllowRasterization as an option for the plot command.

Can anyone reproduce this? Even better: Can anyone tell me what is going on? It is so easy to produce nice graphs with Mathematica, but they are usually destroyed after Export, so that I moved over to exporting data and using pgfplots quite some time ago. But I got puzzled again and want to know what happens here...

• I encountered a similar effect with legends which should have no or white background but get a gray background when exported to PDF. Could you please add OS and version number in case? – Yves Klett Jun 2 '16 at 9:45
• @YvesKlett Good to know I am not the only one. Version/OS is written in the second line ;) – Lukas Jun 2 '16 at 10:14
• Eeek! Sorry for blatant speed-reading 😉 – Yves Klett Jun 2 '16 at 10:49

The problem appears only when you use some specific stylesheets of the notebook. To replicate the issue one can choose standard report from Format->Stylesheets->Report.

To get rid of the issue you can either use some stylesheet without a background for labels or remove the backgroud by manually changing BaseStyle -> {FontSize -> 17, Background -> None}.

• Indeed, I am using the standard report stylesheet. your proposed BaseStyle config solves the problem! Thank you very much, this is great! – Lukas Jun 2 '16 at 10:17

This worked for me (reproduced from my answer on another post on a similar question):

I recently encountered this problem, and none of the above solutions solved my problems (on version 10.3.1.0). However, I have found a solution which worked for me and should be independant of version.

On my version, the problem specifically occurred when using the Report stylesheet, but vanished with the Default one. The trick was to make a custom stylesheet that includes all of the style definitions from Report except the offending Graphics cell definition.

To achieve this practically, I switched to the Default stylesheet on the target notebook, opened a new mathematica notebook with a Report stylesheet , went to Format > Edit stylesheet on both and clicked Report/StandardReport.nb on the latter to load the Report's default cell definitions. Then I copied all the Report's cell definitions over to the Private Style Definitions for XXX.nb notebook and then went in and removed the offending local definition for graphics in Styles for Input and Output Cells as well as changing the background color for Output to white (select the cell then Format > Background Color > White).

Graphics now have a white background for both the image and text labels (an issue raised in another StackMMA question).

This new stylesheet can then be saved Default by following these instructions.