如何消除浮动 tcolorbox 前后的垂直空格?

如何消除浮动 tcolorbox 前后的垂直空格?

如下面的 MCE 所示,tcolorbox只要是floating 类型,a 前后就会添加一些垂直空格。如何去掉这些空格,并获得与非floating 类型相同的垂直空格?

\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}

在此处输入图片描述

答案1

我找到了几种控制上方空间的方法。下方的空间只需添加一个\vspace。也许会有更好的解决方案。

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}

相关内容