0

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:

enter image description here

But this doesn't happen with new chapters or sections:

enter image description here

I feel that the vertical whitespaces that my codeblock produce are ugly, is there a way to fix this?

OiciTrap
  • 171
  • 1
    You have not shown any relevant code so it is hard to debug but presumably you have \flushbottom in 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 \raggedbottom or put the code listing in a float (floats move exactly to avoid bad page breaks like this) – David Carlisle May 10 '18 at 17:47
  • You could try loading tcolorbox with the option breakable and then add the same to the definition of codeblock. This should enable these boxes to break over pages, (Not tested because of lack of a MWE.) – Mike May 10 '18 at 18:06

0 Answers0