如何减少 tcolorbox 中的行间距

如何减少 tcolorbox 中的行间距

我想要具有不同行距的框。在此示例中,它们两个的行距都采用相同的值。

\documentclass{book}
\usepackage{graphicx}
\usepackage{tcolorbox}
\renewcommand{\baselinestretch}{1.5}
\begin{document}
    \begin{tcolorbox}
        This is a very small example for my class. This box has 1.5 of spacing like we can see
    \end{tcolorbox}

    \renewcommand{\baselinestretch}{1.0}
    \begin{tcolorbox}
    This is a very small example for my class. I want this box with spacing between lines of 1.0 and we can see has the same spacing.
\end{tcolorbox}

\end{document}

答案1

像这样?

在此处输入图片描述

\documentclass{book}
\usepackage{graphicx}
\usepackage{tcolorbox}
\renewcommand{\baselinestretch}{1.5}
\usepackage{lipsum}

\begin{document}
\lipsum[11]
    \begin{tcolorbox}
        This is a very small example for my class. This box has 1.5 of spacing like we can see
    \end{tcolorbox}

   \begin{tcolorbox}[fontupper=\linespread{.66}\selectfont]% <---
    This is a very small example for my class. I want this box with spacing between lines of 1.0 and we can see has the same spacing.
    \end{tcolorbox}
\lipsum[12]
\end{document}

答案2

另一个解决方案是:

\documentclass{book}
\usepackage{tcolorbox}
\usepackage{setspace}
\renewcommand{\baselinestretch}{1.0}
\begin{document}

    \begin{tcolorbox}
        This is a very small example for my class. This box has 1.5 of spacing like we can see
    \end{tcolorbox}

    \setstretch{2}
    \begin{tcolorbox}
    This is a very small example for my class. I want this box with spacing between lines of 2.0 and we can see has the same spacing.
\end{tcolorbox}

    \setstretch{1.5}
    \begin{tcolorbox}
    This is a very small example for my class. This box has 1.5 of spacing like we can see
\end{tcolorbox}

\end{document}

相关内容