# Change font size to fit text in column width

I'm trying to create a table with equal width for all columns however if some word needs more space the column width will change. Is it possible to autofit "biiggwwoorrdd" reducing the font size?

Thank you

\centering
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{tabularx}{\textwidth}{ |*{7}{Y|} }
\cline{1-7}
\multicolumn{1}{|c|}{Ano/Mes}
& \multicolumn{3}{c|}{Fantastical aardvarks}
& \multicolumn{3}{c|}{Spelunking elephants}\\
\hline
Foo bar & A & B & C & A & B & C\\
\hline
5  & 87 &  5 &  2 & 82 & 18 & 48\\
6  &  5 & 43 &  4 &  7 & 47 &  4\\
7  &  7 & 18 & 63 &  2 &  9 & 99\\
\hline
2º
& \multicolumn{1}{Y|}{\cellcolor[HTML]{EFEFEF}long test small words}
& \multicolumn{1}{c|}{\cellcolor[HTML]{EFEFEF}biiggwwoorrdd}
& \multicolumn{4}{c|}{\cellcolor[HTML]{EFEFEF}teste?} \\
\hline
\end{tabularx}


• Welcome to TeX.SE. – Mico Dec 20 '18 at 19:15
• Is it not possible to hyphenate the word?? Will be done automatically ... – user2478 Dec 20 '18 at 19:34

You could use the \resizebox* directive, provided by the graphicx package, to force the word to be as wide as \hsize -- the default width of an X column.

I can't help but remark that the result of this exercise looks awful. IF I ever came across a table with similarly terrible font size variations, I would probably start to either laugh, or more likely, cry. For sure, I'd simply stop reading the paper...

\documentclass{article}
\usepackage{tabularx,graphicx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\setlength\tabcolsep{3pt}
\setlength\extrarowheight{2pt} % optional

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{ |*{7}{Y|} }
\hline % NOT "\cline{1-7}"
Ano\slash Mes
& \multicolumn{3}{c|}{Fantastical aardvarks}
& \multicolumn{3}{c|}{Spelunking elephants}\\
\hline
Foo bar & A & B & C & A & B & C\\
\hline
5  & 87 &  5 &  2 & 82 & 18 & 48\\
6  &  5 & 43 &  4 &  7 & 47 &  4\\
7  &  7 & 18 & 63 &  2 &  9 & 99\\
\hline
2º & longer test smaller words
& \resizebox*{\hsize}{!}{biiggwwoorrdd} % <-- new
& \multicolumn{4}{c|}{teste?} \\
\hline
\end{tabularx}
\end{document}