Plots Saved as Different Sizes
7 views (last 30 days)
Show older comments
I'm creating plots in a loop as below:
x=linspace(-2,2);
for i=1:4
h = figure;
plot(x,normpdf(x,0,1));
filename = sprintf('plot%i.eps',i);
hgexport(h,filename);
end
I am then including them in a LaTeX document using this code:
\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.49\textwidth]{plot1}
\includegraphics[width=0.49\textwidth]{plot2}
\includegraphics[width=0.49\textwidth]{plot3}
\includegraphics[width=0.49\textwidth]{plot4}
\end{figure}
\end{document}
The problem is that `plot3.eps` is slightly larger, as seen on the bottom left from the pdf of this LaTeX code:

How can I save plots so that they are all the same sizes? I suspect this is MATLAB's doing and not LaTeX because the MATLAB figure for `plot3` popped up slightly below on my desktop the other figures during the MATLAB run.
2 Comments
Dave Behera
on 25 Mar 2016
Can you open the .eps files in a different software than MATLAB to check if the dimensions really mismatch?
I was able to run your code in MATLAB and got 4 eps files which were identical in terms of size. Then, I used your latex code to create a latex project on https://www.sharelatex.com. The generated pdf had no alignment issues like you reported.
It most likely is not an issue with MATLAB. You may need to add some changes to your latex code to make it work on your system. But, it works fine as it is on sharelatex.com. Do try it out!
John Smith
on 22 Aug 2023
I know it's an old post but I bumped into the very same issue, too (Matlab R2022b, Ubuntu). I ran the same Matlab code on two different computers, and I used the same LaTeX code on Overleaf. Running the Matlab code on the first device gave me plots with different sizes when inserted into the LaTeX code, while I got figures of the same size when the code was executed on another device. I don't know the reason behind it, but it may be related to the graphics renderer Matlab uses to create the plots.
Answers (0)
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!