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

16 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:
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');
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:
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
(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
which will give you relatively wide additional margins:
A more complex way is to use the print2eps function from export_fig on FileExchange, :
%% try print2eps from export_fig on FileExchange
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)




Community Treasure Hunt

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

Start Hunting!