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

76 次查看(过去 30 天)
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?

采纳的回答

Julius Muschaweck
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:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by