# How can I change the font size inside this tcolorbox?

I have this bit of code for a customized tcolorbox (I'm using XeTeX, for font management):

\documentclass[10pt, oneside]{book}
\usepackage[skins]{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{fontspec}
\setmainfont[Path=../../FONTES/,
Variant=1,
BoldItalicFont=cambriaz.ttc,
BoldFont      =cambriab.ttc,
ItalicFont    =cambriai.ttc]
{cambria.ttc}

\newfontfamily\fonteverdana[Path=../../FONTES/,
BoldItalicFont=verdanaz.ttf,
BoldFont      =verdanab.ttf,
ItalicFont    =verdanai.ttf]
{verdana.ttf}

\usepackage{setspace}
\begin{tcolorbox}[enhanced,
breakable,
code={\onehalfspacing},
center title,
title = \fontsize{11}{13}\fonteverdana\textbf{SOLUTION}\vspace{-10pt},
colback=yellow,
colframe=black,
boxrule=.7pt,
arc=0mm,
titlerule=0mm,
colbacktitle=yellow,
coltitle=black,
]{#1\par\vskip8pt}
}{\end{tcolorbox}%

\begin{document}
\begin{completa}

Here I have a number, $2$. As it can be seen it's smaller than it should be. Here's another example:

$$2\times 4 = 8$$

I think that's probably happening because the font is big. But I can't find anyway of changing it.
\end{completa}
\end{document}


When I compile this, I notice the math font becomes too little compared to the main text. Any ideas why? I tried to put some fontsize commands somehow, but couldn't figure it out. See the box below:

• Hmm I think it's not the same problem. Here, I'm probably facing a problem with the XeTeX font management, combined with the tcolorbox config. It's different, I think. Apr 6 '20 at 16:24
• I've deleted the comment. Apr 6 '20 at 17:17
• Off topic: Do not use such a striking color, even for important parts. Use font size, boldness or a more pale color for highlighting.
– ATW
Apr 12 '20 at 17:51
• Oh, thanks for the advice! I'm using this color only for this question, though. On the actual file I'm using a HTML defined one. Apr 12 '20 at 17:56

Here's a way to do it using the the unicode-math package. This requires using a OpenType math font, which limits your choices somewhat. But since you're using Cambria as your main font, I've used Cambria Math in this example. The unicode-math package allows you to create different math versions, so we create one that is scaled to match Verdana and use that in the box.

\documentclass[10pt, oneside]{book}
\usepackage[skins]{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage[math-style=TeX]{unicode-math}
\setmathfont{Cambria Math}[version=main]
\setmathfont{Cambria Math}[version=box,Scale=1.2]

%\setmainfont[Path=../../FONTES/,
%    Variant=1,
%    BoldItalicFont=cambriaz.ttc,
%    BoldFont      ˚=cambriab.ttc,
%    ItalicFont    =cambriai.ttc]
%    {cambria.ttc}
%
\setmainfont{Cambria}
\newfontfamily\fonteverdana[]{Verdana}
%\newfontfamily\fonteverdana[Path=../../FONTES/,
%    BoldItalicFont=verdanaz.ttf,
%    BoldFont      =verdanab.ttf,
%    ItalicFont    =verdanai.ttf]
%    {verdana.ttf}
\usepackage{setspace}

\begin{tcolorbox}[enhanced,
breakable,
code={\onehalfspacing\mathversion{box}},
center title,
title = \fontsize{11}{13}\fonteverdana\textbf{SOLUTION}\vspace{-10pt},
colback=yellow,
colframe=black,
boxrule=.7pt,
arc=0mm,
titlerule=0mm,
colbacktitle=yellow,
coltitle=black,
]{#1\par\vskip8pt}
}{\end{tcolorbox}%
\mathversion{main}
\begin{document}
Regular text:

$2\times 4 = 8$

Example text:
\begin{completa}

Here I have a number, $2$. As it can be seen it's \index{smaller} than it should be. Here's another example:

$2\times 4 = 8$

I think that's probably happening because the font is big. But I can't find anyway of changing it.
\end{completa}
\end{document}


• Hey, thanks for the answer! But let me ask you: isn't there a way to do that globally instead of locally? I mean, I'd have to use a command for every math variable I had. It's quite weird that the math font lowers its size when inside this enviroment, I hope I'd figure out why does that happen.... Apr 12 '20 at 15:51
• It's not that the math font becomes smaller: the math font is small relative to the size of Verdana. If you were using Verdana as your main font you could scale the math to match, but by having a different font inside the box, it's not simple to match the mathsize just inside. Apr 12 '20 at 16:02
• The weird thing is that the math font does get smaller. When I compare it with the math text outside the box, it's smaller. Apr 12 '20 at 16:28
• I'll post a new solution in a second. Apr 12 '20 at 16:28
• Thanks, I really appreciate it!!!! Apr 12 '20 at 16:31