1
$\begingroup$

In Mathematica 13.2, I set the font size of the axes labels to be 14, but after exporting it, in PDF format, I see that the font size is 10.10. What is the reason and how should I fix the font size in the PDF format file.

For example:

a=Plot[Sin[x], {x, 5, 10}, 
 LabelStyle -> Directive[FontFamily -> "Times New Roman", 14]];
Export["C:\\Users\\PC\\Downloads\\22.pdf", a]

The font size of the labels should be 14, but in the PDF file, it is 10.10: Font size changed.

If I copied the figure in Mathematica and pasted it into MS Word, and then save the Word file to PDF. The ticks' font size is 14. So, converting the figure to PDF by Mathematica causes the font size changed.

CouldExport could cause the same problem.

CloudExport[a, "pdf"]

$\endgroup$
7
  • $\begingroup$ You used the wrong option. You need TicksStyle->Directive[{[FontFamily -> "Times New Roman", 14}]. This fixes the size of the figures at the axes. Try and inform us, if it helps. $\endgroup$ May 21, 2023 at 15:50
  • $\begingroup$ @AlexeiBoulbitch Try it and you will get the same result. $\endgroup$
    – Y. zeng
    May 21, 2023 at 15:53
  • $\begingroup$ I did, and got what I expected. If you do not, then the problem is in the step of converting your material to pdf. In general, I do not know how to solve the conversion problem. However, I would first try to rasterize the image before conversion. This may help. $\endgroup$ May 21, 2023 at 18:47
  • $\begingroup$ @AlexeiBoulbitch I updated my question. May you check that if ours' code is the same? $\endgroup$
    – Y. zeng
    May 22, 2023 at 4:42
  • $\begingroup$ Exporting to PDF is like printing, so it uses the Printing environment. That environment sets a non-standard Magnification setting. There isn't a really easy way to alter it when calling Export on something other than a notebook. $\endgroup$
    – ihojnicki
    May 22, 2023 at 17:16

2 Answers 2

3
$\begingroup$

The whole graphic is being set to Magnification->.72 as a result of using the Printout stylesheet environment. So, it's not just the tick labels, but everything is being scaled by a factor of .72. You could set the font size directly to accommodate, but doing so would cause the graphic as a whole to look different since the fonts would be a different relative size to the graphic as a whole. So the best thing to do is to fix the magnification at the level of the entire graphic. This can be done by adding BaseStyle->{Magnification->1} as an option to the functions generating the graphics. E.g.,

a=Plot[Sin[x], {x, 5, 10}, 
 LabelStyle -> Directive[FontFamily -> "Times New Roman", 14],
 BaseStyle->{Magnification->1}];
Export["C:\\Users\\PC\\Downloads\\22.pdf", a]
$\endgroup$
4
  • $\begingroup$ Thanks. May you tell me why the default magnification is 0.72 and where do you know this? How did you know that? As Options[Plot] doesn't contain Magnification specifier. $\endgroup$
    – Y. zeng
    May 23, 2023 at 6:58
  • 1
    $\begingroup$ PDF export uses the default printing environment, which is generally "Printout". Default.nb has the following definition for the "Printout" environment: Cell[StyleData[All, "Printout"], Magnification->0.72]. What my example does isn't to override a Plot default...it's overriding a default inherited from the stylesheet of the notebook that's displaying the result. $\endgroup$
    – John Fultz
    May 26, 2023 at 14:40
  • $\begingroup$ I can find the file Default_8.0.nb, but how I can't find Cell[StyleData[All, "Printout"], Magnification->0.72]. Where is it? Thanks. $\endgroup$
    – Y. zeng
    May 27, 2023 at 1:53
  • $\begingroup$ It's in SystemFiles/FrontEnd/Stylesheets/Default.nb. $\endgroup$
    – John Fultz
    Jun 26, 2023 at 3:32
0
$\begingroup$

You should apply the TicksStyle, rather than LabelStyle, as I have already once explained. Compare two plots:

a = Column[{Plot[Sin[x], {x, 5, 10}, 
    TicksStyle -> Directive[FontFamily -> "Times New Roman", 12], 
    ImageSize -> 300],
   Plot[Sin[x], {x, 5, 10}, 
    TicksStyle -> Directive[FontFamily -> "Times New Roman", 16], 
    ImageSize -> 300]
   }]
Export["C:\Users\PC\Downloads\22.pdf", a]

Have fun!

$\endgroup$
1
  • $\begingroup$ Thanks. But in the output PDF, their font size is 8.65 and 11.50. $\endgroup$
    – Y. zeng
    May 23, 2023 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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