2

As shown by the following MCE, some vertical spaces are added before and after a tcolorbox as soon as it is a floating one. How to get rid of them and obtain the same vertical spaces as the non floating ones?

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.

\begin{tcolorbox}
  Non floating
\end{tcolorbox}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.

\begin{tcolorbox}[float]
  Floating
\end{tcolorbox}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.
\end{document}

enter image description here

1
  • 2
    It's the separation common to all in-text floats, which is controlled by \intextsep. Jan 5, 2022 at 23:49

1 Answer 1

1

I found a couple of ways to control the space above. The space below only adding a \vspace. Perhaps a better solution will come up.

b

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}


\begin{document}
    
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
    vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
    mauris.
    
    \begin{tcolorbox}
        Non floating
    \end{tcolorbox}
    
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
    vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
    mauris.
    
    \begin{tcolorbox}[float, every float=\vspace*{-1ex}]%<<<<<<<<<<<<<<<<<
        Floating I
    \end{tcolorbox}
    \vspace{-1.5ex} %<<<<<<<<<<<<<<<<<
    
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
    vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
    mauris.
    
    \setlength{\intextsep}{2ex plus 1.0pt minus 2.0pt} %<<<<<<<<<<
    \begin{tcolorbox}[float]
        Floating II
    \end{tcolorbox}
    \vspace{-1ex} %<<<<<<<<<<<<<<<<<
    
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
    vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
    mauris.

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .