I've made the command codeblock to show code blocks in a box with:
\newtcblisting[auto counter]{codeblock}[2][]{
sharp corners,
fonttitle = \bfseries,
colframe = gray,
listing only,
listing options = {
basicstyle = \footnotesize\ttfamily,
language = java
},
title = Código \thetcbcounter: #2, #1}
\newcommand\code[1]{
\tikz[baseline=(s.base)]{
\node(s)[fill=gray!20,draw=gray]{\texttt{#1}};
}
}
The problem I have is that sometimes in the previous page it generate whitespaces, I guess Latex tries to make the text density vertically equal, see the following image:
But this doesn't happen with new chapters or sections:
I feel that the vertical whitespaces that my codeblock produce are ugly, is there a way to fix this?


\flushbottomin force which forces latex to stretch the last line to the bottom of the page (because your code listing is unbreakable once you put it in the tikz node) perhaps you want\raggedbottomor put the code listing in a float (floats move exactly to avoid bad page breaks like this) – David Carlisle May 10 '18 at 17:47tcolorboxwith the optionbreakableand then add the same to the definition ofcodeblock. This should enable these boxes to break over pages, (Not tested because of lack of a MWE.) – Mike May 10 '18 at 18:06