2

I want Boxes with different line spacing. In this example both of them take the same value in line spacing.

\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}
5
  • Your question is misleading. You're asking for the spacing of the lines in the title and in the text you're asking about the width? The spacing is done with the font settings. tcolorbox uses the same font for the content of the box as outside of the box, unless specified otherwise
    – user31729
    Apr 24, 2018 at 17:43
  • I'm asking for the spaces of lines in the text Apr 24, 2018 at 17:56
  • 1
    please always post a complete small example, the space between baselines of text depends on the document settings that is the code you have not shown, not on tcolorbox. Apr 24, 2018 at 18:11
  • \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} Apr 24, 2018 at 19:25
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Jul 5, 2018 at 19:43

2 Answers 2

6

like this?

enter image description here

\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}
1
  • 1
    @AndreyVinajera, if you like to have all tcolorbox with with spacing between lines of 1.0 (0.66x1.5 ~ 1), than you can define own tcolorbox which has option fontupper=\linespread{.66}\selectfont.
    – Zarko
    Apr 25, 2018 at 14:10
1

Another solution is:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.