The problem I have is that spacing between a TikZ figure and its caption is bigger that between any other type of pictures and their spacing: huge spacing for TikZ

Obviously, it can be solved by hardcoding \vspace{} or adjusting skip in the preamble or floatwise, which seems a bit tedious and not 'semantical'. But how can it be fixed globally without breaking spacing for other figures?

And, generally speaking, why is Tikz—caption spacing is so big (even without EPS to compare)?



    %tick label style={font=\small},
    %legend style={font=\small},
    ylabel shift={-3pt},
    xlabel shift={-3pt}

% This file was created by matplotlib2tikz v0.6.18.
    % This file was created by matplotlib2tikz v0.6.18.



% This file was created by matplotlib2tikz v0.6.18.
\begin{tikzpicture}[background rectangle/.style={fill=olive!45}, show background rectangle]


legend cell align={left},
legend entries={{$\lambda_{min}$},{$\lambda_{max}$}},
legend style={at={(0.03,0.03)}, anchor=south west, draw=white!80.0!black},
tick align=outside,
tick pos=left,
x grid style={white!69.01960784313725!black},
xmin=0, xmax=5.1,
y grid style={white!69.01960784313725!black},
ylabel={$\log_{10} ||\lambda_i| - 1|$},
ymin=-15, ymax=2,
\addplot [semithick, color1, dotted]
table [row sep=\\]{%
    0   -0.0150784734238995 \\
    0.00340226817878586 -0.0150785247930231 \\
    0.00680453635757171 -0.0150786789065911 \\
    0.0102068045363576  -0.0150789357831926 \\
    0.0136090727151434  -0.0150792954538207 \\
    0.0170113408939293  -0.0150797579618575 \\
    5.08639092728486    1.64658769206306 \\
    5.08979319546364    1.65617254087203 \\
    5.09319546364243    1.66573665825563 \\
    5.09659773182121    1.67528018607781 \\
    5.1 1.6848032640236 \\


Compiles to: enter image description here

But \fbox{} fixes it: enter image description here

  • the spacing from caption will be the same, presumably you have white space in your tikz picture, but as you have provided no usable example it is impossible to say. It is always better to provide a complete test document and show the image of that document not output from a document that's not posted. compare \fbox{\includegraphics{...}} and \fbox{\input{...tikz..}} so you can see the size of the included graphic – David Carlisle Nov 16 '18 at 18:51
  • @DavidCarlisle You're right. I've added a WE that compiles with huge spaces. – homocomputeris Nov 16 '18 at 19:21
  • @DavidCarlisle It turns out that fbox reduces the spacing. – homocomputeris Nov 16 '18 at 19:24
  • oh it's not vertical space it is a white line of a paragraph text tex does tell you it is maxmally bad: Underfull \hbox (badness 10000) in paragraph at lines 40--39 – David Carlisle Nov 16 '18 at 20:40

The image is too wide and forcing a white (underfull) line of text after the paragraph, if you change the last line of pic.tex from




then the output changes from

enter image description here


enter image description here

Basically whenever TeX warns that

Underfull \hbox (badness 10000) in paragraph at lines 40--33

It means something is pretty bad and usually that there is a spurious empty line in the document (10000 is the maximum value of badness, so TeX is warning you that the output is as bad as it can be.....)

  • 1
    Impressive, indeed. ;-) – user121799 Nov 16 '18 at 21:03
  • Thanks! Overfull \hbox (22.30797pt too wide) in paragraph is what it tell me. Why does fbox fix it? Does it force TikZ to be contained and do not spawn that line? – homocomputeris Nov 16 '18 at 21:36
  • @homocomputeris if you use fbox (or mbox) then line breaking at the space is prevented inside the box but actually the main line is then even more overfull, the real fix is to make the the tikz images a bit smaller so that they fit in the page. – David Carlisle Nov 16 '18 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.