# Text auto resize to fit a node

I need to autoscale a text to fit inside a static node which can't change its size.

The code I'm actually using is

\node[text width=3.75cm] at (0.5*\width,\titley) {
\begin{center}
\color{white}\uppercase{\normalsize \textbf{#1}}
\end{center}
};


The result I'm having is this:

I want the text will not exceed the node without manually resize it.

Thanks to any help!

• \resizebox works inside nodes: \documentclass[tikz,border=3mm]{standalone} \begin{document} \begin{tikzpicture} \fill (0,0) rectangle (3.75,1); \node[text width=3.75cm,align=center,text=white] at (0.5*3.75,0.5) { \resizebox{3.75cm}{!}{\MakeUppercase{\normalsize \textbf{abcded}}} }; \end{tikzpicture} \end{document}. It is however not clear to me what the purpose is, do you want to write a macro (and hence the argument #1)? – Schrödinger's cat Sep 21 at 17:54
• Hi, thanks for the response, I've updated the question. The piece of code comes from a macro. – CiuffLegend Sep 28 at 13:28
• Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem. – BambOo Sep 28 at 14:28

You can try with a tcboxfit from tcolorbox package:

\documentclass{article}
\usepackage[most]{tcolorbox}

\begin{document}
\tcboxfit[width=5cm, height=2cm, halign=center, valign=center,
colback=gray!50, colupper=white, colframe=tcbcolback]
{\uppercase{This is my box}}

\tcboxfit[width=5cm, height=2cm, halign=center, valign=center,
colback=gray!50, colupper=white, colframe=tcbcolback]
{\uppercase{This is my box with a long long long long
long long long long long long long long long long text}}

\end{document}