How to add a little white space around the figures by using "print" command?

71 views (last 30 days)
I wish add a few of white space around my .eps figure to avoid that overleaf (compiler: pdfLaTex) cuts it on one side as you can see in the following image (zooming):
Original image:
The code that I use to produce the image is:
figure(2)
plot(...
vTime, convangvel(p(vTime),'rad/s','deg/s'),'-', ...
vTime, convangvel(q(vTime),'rad/s','deg/s'),'-', ...
vTime, convangvel(r(vTime),'rad/s','deg/s'),'-','LineWidth',0.7...
);
axis([0 t_fin -2.5 2.5]);
grid minor;
xlabel('{\it t} (s)'); ylabel('(deg/s)');
legend({'{\it p(t)}','{\it q(t)}','{\it r(t)}'},'location','northeast');
set(gcf,'position',[400, 200, 560, 315],'PaperOrientation', 'landscape');
print('-depsc2','-r600',strcat('es5_vel_ang','.eps'));
Can you suggest me how to modify thi code correctly in order to avoid that issue when I import the figure in overleaf?

Accepted Answer

Julius Muschaweck
Julius Muschaweck on 7 Apr 2021
A simple plot as an example:
figure()
plot([1 2], [1 2]);
set(gcf,'position',[400, 200, 560, 315],'PaperOrientation', 'landscape');
Using print like you did gives the tight bounding box which I dislike for the same reasons for my LaTeX documents:
%% print without rim
print('-depsc2','-r600',strcat('test_tight','.eps'));
(I'm showing screen shots from IrfanView to clarify the bounding boxes)
A simple but unflexible way is to use the '-loose' option of the print command. Like in
%% try print with -loose option
print('-depsc2','-r600',strcat('test_loose','.eps'),'-loose');
which will give you relatively wide additional margins:
A more complex way is to use the print2eps function from export_fig on FileExchange, https://uk.mathworks.com/matlabcentral/fileexchange/23629-export_fig :
%% try print2eps from export_fig on FileExchange
print2eps('test_rim2.eps',gcf,struct('bb_padding',0.01,'regexprep',[],'crop',1));
You need to set 'regexprep' to empty [] to avoid a run time error, and set 'crop' to 1 to enable changing the bounding box at all. Then, 'bb_padding' with 0.01 will add just a little rim, so your figure can almost fill \textwidth in LaTeX:

More Answers (0)

Categories

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

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!