# Text in image scaled to same size as body text

I am working on a research submission and my supervisor requires that any text on my graphs (e.g. axis labels, tick marks etc) are the same size as text in the main body of my report (including captions). In image snippet, all text should be the same size. All text above the caption is in the png file itself.

I am generating images in MATLAB/Python where I can manually set a font size before saving as a png file which overrides the image file that my LaTeX compiler uses.

Here is a minimum version of my tex file. The width argument is where the scaling of my image occurs.

\documentclass{report}

\usepackage{graphicx}
\usepackage{times}

\begin{document}

\begin{figure}
\includegraphics[width=1\linewidth]{plot-fig}
\caption{This is my caption}
\end{figure}

This is my body text

\end{document}


And my MATLAB code to produce the png. It is in the same directory as the LaTeX. You can see the fontsize variable which I am manually changing.

figure
plot(1:5, 2*(1:5))
xlabel('This is my x label')
ylabel('This is my y label')
title('This is my title')

fontsize = 18;
ax = gca;
set(gca, 'FontSize', fontsize)

saveas(gcf, 'plot-fig.png')


My current solution is trial and error but this simply drives me insane: generate image, compile LaTeX, manually check text sizes by eye, adjust font size, repeat. This is further complicated by the scaling of images. Sometimes I need the images to take up two columns, other times a single column (and due to margins, the scaling is not a factor of 2). Also the dimensions of images are not always a consistent ratio as I am told to reduce the height of some images while keeping the same width (to avoid wasting space).

I would really appreciate a solution that could automate this process and give me some assurance that the font sizes are consistent.

• Welcome to TeX.SE. As you provide no actual LaTeX code and provide no information about the document class, the main font size, the font family used in the body of the family, the font family used in the graphics, or the method (methods?) by which graphs are (a) scaled and (b) included in the document, it's well-nigh impossible to provide specific advice. That said, I'd say that your adviser's requirement that "any text on my graphs (e.g. axis labels, tick marks etc) [have] the same size as text in the main body of my report" is preposterous and utterly misguided. – Mico Oct 7 '19 at 5:54
• @Mico Thanks for the feedback. I have updated my question to give some more details including LaTeX/MATLAB code and an image snippet. I will remember your advice for future questions. – wgb22 Oct 7 '19 at 6:41
• Related (for the Matlab part): tex.stackexchange.com/questions/3995/… – Marijn Oct 7 '19 at 6:59
• it is best of course to avoid png for graphs or text, and use a scalable format such as pdf, but in either case your problem is [width=1\linewidth] which scales by an arbitrary amount. Remove that and include the image at its natural size, then in matlab use the same text size as in your document. – David Carlisle Oct 7 '19 at 7:01
• @DavidCarlisle So maybe I could set the figure size to conform with the value of 1\linewidth when I create it in MATLAB. Then the figure should be scaled correctly when I do \includegraphics? – wgb22 Oct 7 '19 at 7:16

It is best of course to avoid png for graphs or text, and use a scalable format such as pdf, but in either case your problem is [width=1\linewidth] which scales by an arbitrary amount.