EPS Figure Bounding Box

9 views (last 30 days)
Robin
Robin on 30 Jul 2015
Answered: prabhat kumar sharma on 14 Apr 2024 at 10:57
Dear all, I have a problem when I create a EPS figure which I want to include in Latex. Somehow I am unable to place a caption above the figure created with Matlab. It gets overwritten by whitespace. I have created a minimum working example. The figure in matlab is created according the following code:
plot(1:10)
title('A line')
print('test','-depsc2')
And the corresponding latex file:
\documentclass[a4paper]{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\caption{Caption is overwritten}
\includegraphics[width=\textwidth]{test.eps}
\end{figure}
\end{document}
No caption is visible in the output pdf. I am using graphicx package and a dvi-ps-pdf chain.
It seems to be an issue with the bounding box values. If I add go to the draft mode of graphicx (\usepackage[draft]{graphicx} ) the caption appears.
Thanks for any help. Best, Robin

Answers (1)

prabhat kumar sharma
prabhat kumar sharma on 14 Apr 2024 at 10:57
Hi Robin,
I understand that you're attempting to use an EPS figure created through MATLAB in your LaTeX document. I tried to reproduce the issue but didn't encounter the same problem in my document. It's possible that the bounding box is not correctly defined, leading LaTeX to allocate incorrect space for the figure. This misallocation can result in overlays or other layout issues, such as your caption being overwritten by whitespace.
1. Adjust the Bounding Box Manually
You can manually edit the EPS file to correct the bounding box values. Open the EPS file in a text editor, look for the %%BoundingBox: line, and adjust the values. This might require some trial and error to get right.
%%BoundingBox: 40 19 385 304
2. Convert EPS to PDF
Since you're using the dvi-ps-pdf chain, another approach is to convert the EPS file to PDF and then use the PDF version in your LaTeX document. This can be done using tools like epstopdf: https://www.mathworks.com/matlabcentral/fileexchange/5782-eps2pdf
3. Try Considering using the figure environment in LaTeX without specifying the [h] placement to give LaTeX more flexibility in figure placement, which might mitigate the issue.
I hope it helps to resolve your issue.

Categories

Find more on Printing and Saving in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!