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

19 ビュー (過去 30 日間)
Wissem-Eddine KHATLA
Wissem-Eddine KHATLA 2024 年 4 月 4 日
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 件のコメント
Jeff Miller
Jeff Miller 2024 年 4 月 5 日
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 2024 年 4 月 7 日
@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 !

サインインしてコメントする。

回答 (1 件)

Ayush Anand
Ayush Anand 2024 年 4 月 4 日
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 件のコメント
Wissem-Eddine KHATLA
Wissem-Eddine KHATLA 2024 年 4 月 4 日
編集済み: Wissem-Eddine KHATLA 2024 年 4 月 4 日
@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,

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by