如下面的 MCE 所示,tcolorbox
只要是float
ing 类型,a 前后就会添加一些垂直空格。如何去掉这些空格,并获得与非float
ing 类型相同的垂直空格?
\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
。也许会有更好的解决方案。
\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}