# How to match text fontsize in eps/pdf graphics?

I have about 100 eps/pdf drawings in my textbook on physics. They are produced mainly using Wolfram Mathematica and then edited in CorelDraw. I spent many hours of my time to match font size in the drawings with the text font size. Unfortunately, the publishing house has reedited my eps files. For some reason, which the publishing house cannot explain clearly (they just say that they always edit graphics themselves), they have changed the font in the graphic files, introduced lot of errors, so that I am really angry. StackExchange is not a proper place to list all my claims to the quality of their work, I just want to make sure that similar troubles will not happen in the future since I hope that it was not my last book.

I tried to draw the pictures (in CorelDraw) in the same scale as they should go to the book and use same font size as in the book.

Is the a better approach?

Could someone outline some rules on how to prepare a drawing in an external graphics programs to guarantee approximately same font size as in the main text of a book?

Is there a method to fix font size when scaling eps or pdf image in \includegraphcs?

Should the font size in a figure be the same as in the text or it should be smaller/larger?

I also did figures for a book. After struggling a lot I realized that the only way was to export the figures from Mathematica in the actual dimensions they will have in the book. Specify explicitly the size of the font, and export in the right resolution.

Also, the guideline I know about for font size in figures is that they should be close to equal to the font size of the text, to guarantee readability.

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – texenthusiast Aug 20 '13 at 17:03

## Is there a better approach?

I won't claim to know the definitive workflow, because the scope of your problem seems a bit too broad for that. You might want to consider switching to TikZ/PGF ;-)

## Is there a method to fix font size when scaling eps or pdf image in \includegraphcs?

If you can provide all your graphics in EPS format, you might want to check out the PSfrag system, which, quoting the authors,

[a]l­lows LATEX con­struc­tions (equa­tions, pic­ture en­vi­ron­ments, etc.) to be pre­cisely su­per­im­posed over En­cap­su­lated PostScript fig­ures, us­ing your own fa­vorite draw­ing tool to cre­ate an EPS fig­ure and plac­ing sim­ple text ‘tags’ where each re­place­ment is to be placed, with PSfrag au­to­mat­i­cally re­mov­ing these tags from the fig­ure and re­plac­ing them with a user spec­i­fied LATEX con­struc­tion, prop­erly aligned, scaled, and/or ro­tated.

Thus you can define the text and text size in a (La)TeX document, where you include your EPS at the desired scale. You then just have to place the corresponding tags in your EPS at the correct positions and won't have to worry about the actual text appearance anymore. There's a nice example aiming at your general problem in Section 7 of the package documentation.

## Should the font size in a figure be the same as in the text or it should be smaller/larger?

IMHO, you should try to stick to the size of the main body unless there's a good reason not to. You should definitely stick to the same typeface as the text. Also, make sure to use fonts in the proper optical size and not to scale text elements. There are some nice guidelines in Section I.7.4 "Consistency Between Graphics and Text" of the TikZ/PGF manual

• Sorry, I don't believe that TizZ can compete with Wolfram Mathematica. – Igor Kotelnikov Mar 1 '13 at 11:08

Well at least for Mathematica, there is a trick. Though that might be better to post that on http://matematica.stackexchange.com

If you have an Image and want to be sure, that it has a certain font size, you have to know 2 things: It's actual size (I'm european, to i'll stick to cm) and its resolution (in dpi).

Let's say you plottet something using A = Plot[..., FontSize->12]), hence ´A is your image. Then

Export["myImage.eps", Show[A, ImageSize -> mySize*72/2.54], Background -> None, ImageResolution -> myDPI, AllowRasterization -> False];

exports the graphic in mySize cm using myDPI dpi as a resolution (on transparent background). Of course that requires re-rendering/export for different sizes of the graphic. Same works of course (without AllowRasterization) for png graphics, though then the Letters get Rasterized.

If you than include the graphic using includegraphics using width= with your mySize in cm as size you have the correct font size you prefer. If you specify ImageSize-> {somevalue} --- of course --- you have to use height= in LaTeX.

I prefer a slightly smaller Font size (say 8) for graphics text, having a text font size of 11pt.

On the other hand, TikZ works also quite nice with overlays, which I'm also using sometimes, see Drawing on an image with TikZ.

• Why does ImageResolution play any role in vector graphics? I tried changing it for my pdf and nothing changed in the final document. – Johu Aug 29 '15 at 14:22
• Oh, that's quite a while ago, that I used that command, maybe that's only for the png, i'm not sure (and have no Mathematica at hand atm). – Ronny Aug 29 '15 at 15:58

Is there a better approach ?

The direct/best/elegant would be to use Tikz/pstricks/asymptote/pgfplots/gnuplot to "code the figures" so that figure size, text and figure font equality will be taken care of automatically as LaTeX can run all these using packages.

The semi-automatic would be psfrag commands to replace the embedded tags in EPS generated from third-party. Remember to place a X,Ytag at location where you want the text to be placed while exporting to EPS. You can use pstool package, a sup­port for ps­frag commands to run within pdflatex engine.

Could someone outline some rules on how to prepare a drawing in an external graphics programs to guarantee approximately same font size as in the main text of a book ?

It's always wise enough to save the figure in the Target size required not more not less. Otherwise scaling effects/font size come into play.

Good TeX.SX Reference: What do people use for modifying figures?

Classical Reference: Using Imported Graphics in LaTeX and pdfLaTeX by Keith Reckdahl

Is there a method to fix font size when scaling eps or pdf image in \includegraphcs ?

No, Not in my knowledge. Unless you have source code for figure in Tikz/pstricks as mentioned in 1st question.

Should the font size in a figure be the same as in the text or it should be smaller/larger ?

It's your choice. You can have the same order 12pt text and 11pt Figure annotations depending on requirements. But keep in mind the figure size while exporting.

By the way never try editing too many times in multiple graphics software. From Mathematica to CorelDraw etc.. I think Mathematica can export to EPS with 'X' and 'Y' tags embedded to replace with real text using psfrag commands. There is also MathPSfrag command supported in auto-pst-pdf package to include Mathematica figures. Inkscape incase of emergencies.

Is the a better approach?

I use the pgf package \usepackage{pgf} to scale the figure.

\begin{figure}[!h]
\centering
\makebox[\textwidth]{\scalebox{0.5}{\input{image.pgf}}}
\caption{Caption here}
\label{fig:spec}
\end{figure}

Once you have used a scale facotor you have to change the font size so that it matches the font size of your text. For doing that you have to edit the .pgf file.

For instance if this is a text line of your pgf file:

\pgftext[x=2.447742in,y=1.934261in,,base]{\color{textcolor}\sffamily\fontsize{10.000000}
1. First remove the font: \sffamily so the .pgf figure will use the font of your document. What I usually do is to do a "find and replace", replacing all the font command with a white space.

2. Then do another find and replace to change the \fontsize according the folowing formula pgf_font_size = document_font_size/scale_factor

Could someone outline some rules on how to prepare a drawing in an external graphics programs to guarantee approximately same font size as in the main text of a book?

If you already know the dimension you just have to keep the same font size from the begingig when you draw the figure and specify the figure dimension.

Should the font size in a figure be the same as in the text or it should be smaller/larger?

Depends on your needs, I usually use the same font of the caption.

• you should not promote the use of the center env to center inside a float. There \centering should be used (command not env), since center adds vspacing above and below as does the float. – daleif Dec 30 '16 at 9:55