Change the font size in a table or settings of the table
I see mainly tow suggestions
- Allow the
tcolorbox
to trample on the margins by enlarging it's width. - Reduce the font size
%
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{geometry}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
%\DeclareFloatFont{tiny}{\tiny}
\tcbuselibrary{skins}
%\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[ht]
\centering
\begin{tcolorbox}[tab2,
tabularx={X|*{14}{|c}},
title=Bestandteile von T/P92,boxrule=0.5pt,
,grow to left by=0.5cm,
grow to right by=0.5cm]
& C & Mn & P & S & Si & Cr & W & Mo & V & Cb(Nb) & N & B & Al & Ni \\\hline\hline
min~\% & 0.07& 0.3 & Ns & Ns & Ns& 8.5& 1.5 & 0.3 & 0.15 & 0.04& 0.03 & 0.001 & Ns & Ns \\
max~\% & 0.13& 0.02 & 0.01 & 0.5 & 9.5& 2& 0.6 & 0.6 & 0.25 & 0.09& 0.07 & 0.006 & 0.04 & 0.4\\\hline\hline
\end{tcolorbox}
\caption{Caption}
\label{tab:my_label}
\end{table}
\begin{table}[ht]
\centering
\begin{tcolorbox}[tab2,
tabularx={X|*{14}{|c}},
title=Bestandteile von T/P92,boxrule=0.5pt,
fontupper=\small\sffamily,
% or fontupper=\footnotesize \sffamily,
]
& C & Mn & P & S & Si & Cr & W & Mo & V & Cb(Nb) & N & B & Al & Ni \\\hline\hline
min~\% & 0.07& 0.3 & Ns & Ns & Ns& 8.5& 1.5 & 0.3 & 0.15 & 0.04& 0.03 & 0.001 & Ns & Ns \\
max~\% & 0.13& 0.02 & 0.01 & 0.5 & 9.5& 2& 0.6 & 0.6 & 0.25 & 0.09& 0.07 & 0.006 & 0.04 & 0.4\\\hline\hline
\end{tcolorbox}
\caption{Caption}
\label{tab:my_label2}
\end{table}
\end{document}
Building upon Hafid Boukhoulda's solution, I have slightly decreased the tabcolsep
. With this, the table can fit into the textwidth without the need to decrease the font size and without overfull boxes. Please note that I have also used the geometry
package to get a wider textblock.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{geometry}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[ht]
\centering \setlength{\tabcolsep}{5.25pt}
\begin{tcolorbox}[tab2,
tabularx={X|*{14}{|c}},
title=Bestandteile von T/P92,boxrule=0.5pt,
%fontupper=\small\sffamily,
]
& C & Mn & P & S & Si & Cr & W & Mo & V & Cb(Nb) & N & B & Al & Ni \\\hline\hline
min~\% & 0.07& 0.3 & Ns & Ns & Ns& 8.5& 1.5 & 0.3 & 0.15 & 0.04& 0.03 & 0.001 & Ns & Ns \\
max~\% & 0.13& 0.02 & 0.01 & 0.5 & 9.5& 2& 0.6 & 0.6 & 0.25 & 0.09& 0.07 & 0.006 & 0.04 & 0.4\\\hline\hline
\end{tcolorbox}
\caption{Caption}
\label{tab:my_label2}
\end{table}
\end{document}
If you don't want to use the geometry
package you might be interested in one of the following two suggestions:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}
\begin{document}
\begin{table}[ht]
\centering \setlength{\tabcolsep}{2.99pt}
\begin{tcolorbox}[tab2,
tabularx={X|*{14}{|c}},
title=Bestandteile von T/P92,boxrule=0.5pt,
fontupper=\small\sffamily,
]
& C & Mn & P & S & Si & Cr & W & Mo & V & Cb(Nb) & N & B & Al & Ni \\\hline\hline
min~\% & 0.07& 0.3 & Ns & Ns & Ns& 8.5& 1.5 & 0.3 & 0.15 & 0.04& 0.03 & 0.001 & Ns & Ns \\
max~\% & 0.13& 0.02 & 0.01 & 0.5 & 9.5& 2& 0.6 & 0.6 & 0.25 & 0.09& 0.07 & 0.006 & 0.04 & 0.4\\\hline\hline
\end{tcolorbox}
\caption{Caption}
\label{tab:my_label2}
\end{table}
\begin{table}[ht]
\centering \setlength{\tabcolsep}{3.65pt}
\begin{tcolorbox}[tab2,
tabularx={X|*{14}{|c}},
title=Bestandteile von T/P92,boxrule=0.5pt,
fontupper=\footnotesize\sffamily,
]
& C & Mn & P & S & Si & Cr & W & Mo & V & Cb(Nb) & N & B & Al & Ni \\\hline\hline
min~\% & 0.07& 0.3 & Ns & Ns & Ns& 8.5& 1.5 & 0.3 & 0.15 & 0.04& 0.03 & 0.001 & Ns & Ns \\
max~\% & 0.13& 0.02 & 0.01 & 0.5 & 9.5& 2& 0.6 & 0.6 & 0.25 & 0.09& 0.07 & 0.006 & 0.04 & 0.4\\\hline\hline
\end{tcolorbox}
\caption{Caption}
\label{tab:my_label2}
\end{table}
\end{document}
I propose using tabular*
together with siunitx
.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{tabularx}
\usepackage{array}
\usepackage{siunitx,booktabs}
\usepackage{colortbl} % better passing table to xcolor
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\makeatletter
\tcbset{
tab2/.style={
enhanced,
fonttitle=\bfseries,
fontupper=\normalsize\sffamily,
colback=yellow!10!white,
colframe=red!50!black,
colbacktitle=Salmon!40!white,
coltitle=black,
center title
},
tabular*/.style={%
boxsep=\z@,top=\z@,bottom=\z@,leftupper=\z@,rightupper=\z@,
toptitle=1mm,bottomtitle=1mm,boxrule=0.5mm,
before upper*={\arrayrulecolor{tcbcolframe}\def\arraystretch{1.1}%
\expandafter\tcb@hack@currenvir\csname tabular*\endcsname{\linewidth}{#1}},
after upper*=\csname endtabular*\endcsname\arrayrulecolor{black}},
}
\makeatother
\newcolumntype{T}[1]{S[table-format=#1]}
\begin{document}
\begin{table}[ht]
\centering
\setlength{\tabcolsep}{0pt}
\sisetup{detect-all}
\begin{tcolorbox}[
tab2,
tabular*={
@{\extracolsep{\fill}\hspace{2pt}}
l *{3}{T{1.2}} *{5}{T{1.1}} *{3}{T{1.2}} T{1.3} T{1.2} T{1.1}
@{\hspace{2pt}}
},
title=Bestandteile von T/P92,
boxrule=0.5pt
]
& {C} & {Mn} & {P} & {S} & {Si} & {Cr} & {W} & {Mo} & {V} & {Cb(Nb)} & {N} & {B} & {Al} & {Ni}
\\
\midrule
min\% & 0.07& 0.3 & {Ns} & {Ns} & {Ns} & 8.5 & 1.5 & 0.3 & 0.15 & 0.04 & 0.03 & 0.001 & {Ns} & {Ns}
\\
max\% & 0.13& 0.02 & 0.01 & 0.5 & 9.5 & 2 & 0.6 & 0.6 & 0.25 & 0.09 & 0.07 & 0.006 & 0.04 & 0.4
\\
\end{tcolorbox}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
The tabular*
style is not available with the standard tcolorbox
, but it would be an interesting addition.
After looking at the typeset table, it will be immediately apparent whether reducing the font size with \small
or \footnotesize
is necessary.