Clear Filters
Clear Filters

Matlab figures of same size still appear different in a LaTex document

17 views (last 30 days)
Hello,
I am trying to import 2 Matlab figures as EPS files to put in a LateX document side by side. I have checked the size of the figures : it is the same. However, in my Latex PDF, I have a small vertical shift between the 2 (image below), and I don't understand if it is a LateX problem or a Matlab one.
Assuming, it is a possible Matlab error, I am asking my question here but feel free to say that it could be related to Latex so i can delete my post.
Thank you in advance for your help,
Best regards,
  2 Comments
Jeff Miller
Jeff Miller on 5 Apr 2024
If it is an option, it might be more convenient to include both panels in a single MATLAB figure using tiledlayout or subplot. That way you only have one eps or pdf file to include in your LaTex document, and the alignment between panels should be managed properly by MATLAB (i.e., I've never had alignment problems with multi-panel figures).
Wissem-Eddine KHATLA
Wissem-Eddine KHATLA on 7 Apr 2024
@Jeff Miller Thank you for your proposition : I will try to do as you suggested but to be honest I am not a big fan of `subplot` and `tiledlayout` : for some reason I am not very at ease with handling figures using these options but if it's the only way to avoid this bug I will give it a try. Thank you !

Sign in to comment.

Answers (1)

Ayush Anand
Ayush Anand on 4 Apr 2024
Hi,
The error could be arising in either MATLAB or Latex. You would have to check the vertical alignment in minipage or any environment you are using to align the figures on the Latex side.
On the MATLAB side, you can double check if the actual figure doesn't have any additional whitespaces on the sides. You can adjust the figure's properties before exporting to minimize any unnecessary margins through the following lines of code:
fig = gcf; % Get figure handle
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];
print(fig, 'filename.eps', '-depsc');
You can refer to the following MATLAB answer for more insights on this:
Hope this helps!
  1 Comment
Wissem-Eddine KHATLA
Wissem-Eddine KHATLA on 4 Apr 2024
Edited: Wissem-Eddine KHATLA on 4 Apr 2024
@Ayush Anand Thank you for your answer : i have determined that this is indeed a Matlab issue because when I export the figures as PDF not EPS (as I was doing before) the 2 are aligned in the LaTex document. However, I keep having bothering white margin around the figures in the PDF file created by MATLAB. The irony is that when I use exportgraphics to delete the margins, I end up with the same problem as EPS files which is really really strange. Seems like nothing but it's really annoying since I am trying to work systematically with MATLAB to save figures...
Thank you again for your help,

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!