这是我提到的 MWE,供您参考。
如果表格宽度超出文本宽度,则日志文件将包含该信息Overfull \hbox (73.38211pt too wide)
。需要将此值存储73.38211pt
在一个命令中。命令的宽度\wd\stubbox
仅存储在红色突出显示框的点处。
但是,我需要表格的总宽度(包括溢出的文本区域),如下图所示。
以下是如何在一个命令中存储超额值。我将非常感谢您的建议。
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}
答案1
目前还不完全清楚您的问题是什么以及表格应该是什么样子。
我的回答是预期(基于加载的 threeparttable):
- 表格应保留其自然宽度(由列的宽度决定)
- 标题宽度可以等于表格宽度
- 表格注释的宽度可以等于表格宽度
- 编译时不会抛出警告
\hbox (.... too wide)
为了达到上述预期目标,我建议使用changepage
宏局部扩大的包\textwidth
,使用talltblr˛of
tabularray package instead of
threeparttable`。
\documentclass{book}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document
\usepackage[font=small, labelfont=bf]{caption}
\usepackage[strict]{changepage}
\usepackage{xcolor}%
\definecolor{titlecolor}{cmyk}{1,1,0,0.1}
\definecolor{tablegray}{cmyk}{0,0,0,0.10}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\NewTblrTheme{tabcaptionof}%
{
\DefTblrTemplate{caption}{default}%
{\addtocounter{table}{-1}%
\captionof{table}{\InsertTblrText{caption}}}
}
\SetTblrStyle{remark}{font=\footnotesize}
\SetTblrStyle{note}{font=\footnotesize}
\usepackage{hyperref}
\begin{document}
\setcounter{chapter}{3}
\lipsum[66]
\begin{table}[htb]
\captionsetup{skip=-0.5ex}
\begin{adjustwidth*}{}{-\marginparwidth}
\begin{talltblr}[
theme = tabcaptionof,
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},
note{1} = {the distribution ID $i\in[1,6]$ for six implemented distributions, (2) the model parameters depending on the chosen distribution.},
note{2} = {the model parameters depending on the chosen distribution, and},
note{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.},
]{colspec = {l c c *{2}{S[table-format=1.2]} *{8}{Q[c]} },
row{1} = {guard, font=\bfseries, bg=titlecolor,fg=white},
cell{1}{2-Z} = {font=\bfseries\itshape},
row{odd[2]} = {bg=tablegray}
}
Distribution ID
& card & & sp$_1$
& sp$_2$
& sp$_3$
& sp$_4$
& a$_1$
& a$_2$
& a$_3$
& a$_4$
& a$_5$
& a$_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 \\
Diagonal (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 \\
Gaussian (Figure \hyperref[b-3548732-003-fig-002]{\textcolor{titlecolor}{3.2}c})
& 2000 & 2 & 0.1 & 0.1 & & & 1 & 0 & 0 & 0 & 1 & 0 \\
Sierpinski (Figure \hyperref[b-3548732-003-fig-003]{\textcolor{titlecolor}{3.3}a})
& 1000 & 2 & 0.01 & 0.01 & & & 1 & 0 & 0 & 0 & 1 & 0 \\
Bit (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 \\
Parcel (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{talltblr}
\end{adjustwidth*}
\end{table}
\lipsum[11]
\end{document}