[Tex/LaTex] setting text size inside tcolorbox

fontsizetcolorbox

How can I set the size of all the text that appears inside a tcolorbox to a different size? I have tried size=small in the options of the tcolorbox to no effect.

\begin{tcolorbox}[size=small]
some text
\end{tcolorbox}

Best Answer

It can be done by setting a hook at the beginning of the tcolorbox environment with the aid of etoolbox package. See the following:

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{lipsum}
\usepackage{etoolbox}
\AtBeginEnvironment{tcolorbox}{\small}

\begin{document}

\lipsum[2]
\begin{tcolorbox}%[size=small]
\lipsum[2]
\end{tcolorbox}

\end{document}

enter image description here

new solution based on comment

As you mentioned, previous solution makes all boxes' font size small, but with fontupper option you can set font size for upper part of tcolorbox and with fontlower for the lower part.

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{mybox}{fontupper=\footnotesize}

\begin{document}
\begin{tcolorbox}[fontupper=\tiny, fontlower=\Large]
This is the upper part. 
\tcblower
This is the lower part.
\end{tcolorbox}

This is normal size font. 

\begin{mybox}
\lipsum[2]
\end{mybox}

\end{document}

enter image description here

Related Question