Here is the MWE I mentioned for your reference.
If the table width exceeds the text width, the log file will contain the information Overfull \hbox (73.38211pt too wide). It is necessary to store this value 73.38211pt in one command. The width of the \wd\stubbox command is only stored at the points of the red highlighted boxes.
However, I need the total width of the table including overfilled text areas, as shown in the picture below.
Here is how to store the overfull value stored in one command. I would appreciate your advice.
MWE:
\documentclass{book}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{xpatch}
\usepackage{tabularx}
\usepackage[table]{xcolor}%
\usepackage{hyperref}
\usepackage{array}
\usepackage{dcolumn}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{showframe}
\newcolumntype{P}[1]{>{\raggedright\let\}p{#1}}
\newcommand{\tablabel}[2]{\def\tablename{#1}\def\thetable{#2}}
\newcommand{\tableheading}[1]{{\fontsize{9.5pt}{11.5pt}\selectfont\textcolor{white}{\textbf{#1}}}}
\makeatletter
\gdef\tablenotesalign{\appto\TPTnoteSettings{\topsep0pt\leftmargin0pt\rightmargin0pt}}
\makeatother
\definecolor{titlecolor}{cmyk}{1,1,0,0.1}
\definecolor{tablegray}{cmyk}{0,0,0,0.10}
\renewcommand\fbox{\fcolorbox{red}{white}}
\newbox\stubbox
\newcommand{\stubwidth}[1]{%
\global\setbox\stubbox\hbox{#1}%
\ifdim\wd\stubbox>\dimexpr\textwidth-1pt%
\fboxrule2pt\fbox{\hfill\hbox{#1}}%
\appto\TPTnoteSettings{\leftmargin0pt\rightmargin0pt}
\else%
\appto\TPTnoteSettings{\leftmargin0pt\rightmargin0pt}
#1\fi}
\begin{document}
\begin{table}[!b]
\tablabel{Table}{3.1}
\caption{Identifiers for the six sample datasets shown in this paper. For simplicity, all of them use the identity transformation (affine) matrix}\label{b-3548732-003-tab-001}\stubwidth{\tablenotesalign
\begin{threeparttable}
\rowcolors{1}{tablegray}{}\begin{tabularx}{\linewidth}{P{105pt}cccccccccccc}
\rowcolor{titlecolor}\tableheading{Distribution ID} & \tableheading{$\textit{\textbf{card}}$} & \tableheading{$\textit{\textbf{d}}$} & \tableheading{$\boldsymbol{sp}{\textbf{1}}$} & \tableheading{$\boldsymbol{sp}{\textbf{2}}$} & \tableheading{$\boldsymbol{sp}{\textbf{3}}$} & \tableheading{$\boldsymbol{sp}{\textbf{4}}$} & \tableheading{$\boldsymbol{a}{\textbf{1}}$} & \tableheading{$\boldsymbol{a}{\textbf{2}}$} & \tableheading{$\boldsymbol{a}{\textbf{3}}$} & \tableheading{$\boldsymbol{a}{\textbf{4}}$} & \tableheading{$\boldsymbol{a}{\textbf{5}}$} & \tableheading{$\boldsymbol{a}{\textbf{6}}$}\
{Uniform (Figure \hyperref[b-3548732-003-fig-002]{\textcolor{titlecolor}{3.2}}a)} & {1000} & {2} & {0.02} & {0.02} & & & {1} & {0} & {0} & {0} & {1} & {0}\
{{D}iagonal (Figure \hyperref[b-3548732-003-fig-002]{\textcolor{titlecolor}{3.2}}b)} & {1000} & {2} & {0.01} & {0.01} & {0.2} & {0.1} & {1} & {0} & {0} & {0} & {1} & {0}\
{{G}aussian (Figure \hyperref[b-3548732-003-fig-002]{\textcolor{titlecolor}{3.2}}c)} & {2000} & {2} & {0.1} & {0.1} & & & {1} & {0} & {0} & {0} & {1} & {0}\
{{S}ierpinski (Figure \hyperref[b-3548732-003-fig-003]{\textcolor{titlecolor}{3.3}}a)} & {1000} & {2} & {0.01} & {0.01} & & & {1} & {0} & {0} & {0} & {1} & {0}\
{{B}it (Figure \hyperref[b-3548732-003-fig-003]{\textcolor{titlecolor}{3.3}}b)} & {5000} & {2} & {0.01} & {0.01} & {0.3} & {10} & {1} & {0} & {0} & {0} & {1} & {0}\
{{P}arcel (Figure \hyperref[b-3548732-003-fig-003]{\textcolor{titlecolor}{3.3}}c)} & {1000} & {2} & {0.2} & {0.2} & & & {1} & {0} & {0} & {0} & {1} & {0}\
\end{tabularx}
\end{threeparttable}}
\begin{tablenotes}
\item (1) the distribution ID $i\in[1,6]$ for six implemented distributions, (2) the model parameters depending on the chosen distribution.
\item (2) the model parameters depending on the chosen distribution, and
\item (3) a transformation matrix used later by the transformer. The first two components of the dataset descriptor, i.e., distribution ID and model parameters, are passed to the generator which generates the desired dataset. After that, the transformer applies an affine transformation on the generated data according to the third component of the dataset descriptor.
\end{tablenotes}
\end{table}
\end{document}

