当我嵌套 tabular* 时, \hline 不够长,如何解决?

当我嵌套 tabular* 时, \hline 不够长,如何解决?
\documentclass[10pt,UTF8,openany]{book}     
\usepackage{float}
\begin{document}
        \begin{table}[H]
            \caption{Specifying the Type of a Literal}
            \label{tab:specify literal type}
            \centering
            \begin{tabular*}{\textwidth}{ @{} @{\extracolsep{\fill}} | c | @{}}
                \hline
                \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} lll}
                    \multicolumn{3}{ c }{Character and Character String Literals} \\
                     Prefix & Meaning & Type \\
                    u & Unicode16 & char16\_t \\
                    U & Unicode32 & char32\_t \\
                    L & wide character  & wchar\_t \\ 
                    u8 & UTF-8(string literal only) & char \\
                \end{tabular*} \\
                \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} llll }
                    \multicolumn{2}{ c }{Integer Literals}  & \multicolumn{2}{ c }{Floating-Point Literals} \\
                    Suffix & Minimum Type & Suffix & Type \\
                    u or U & unsigned & f or F & float \\
                    l or L & long & l or L & long double \\
                    ll or LL & long long & {} & {} \\
                \end{tabular*} \\
                \hline
            \end{tabular*}              
        \end{table}
\end{document}

在此处输入图片描述

答案1

主要问题是您@{}仅使用 来抑制最外层环境边缘的空白填充tabular*,而不抑制两个内部环境的边缘空白填充。构造的总宽度最终为\textwidth+2\tabcolsep,可以通过运行代码并将右侧垂直线的位置与页码的位置进行比较来验证。

我建议您 (a) 省略两条外部垂直线,(b) 设置\tabcolsep0pt,以及 (c) 为标题提供更多视觉结构。您的读者会感激您的努力 - 并且可能会花更多时间真正吸收表格材料...

在此处输入图片描述

\documentclass[10pt,UTF8,openany]{book} 
\usepackage{float}
\usepackage{booktabs} % for \toprule, \bottomrule, \cmidrule, & \addlinespace
\usepackage[skip=0.333\baselineskip]{caption}
\begin{document}

\begin{table}[H]
\setlength\tabcolsep{0pt} % <-- new
\caption{Specifying the Type of a Literal}
\label{tab:specify_literal_type}
%%\centering % <-- not necessary
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}c}
\toprule
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lll}
\multicolumn{3}{c}{Character and Character String Literals} \\
\cmidrule{1-3}
Prefix & Meaning & Type \\
\cmidrule{1-1} \cmidrule{2-2} \cmidrule{3-3}
u & Unicode16 & char16\_t \\
U & Unicode32 & char32\_t \\
L & wide character  & wchar\_t \\ 
u8 & UTF-8 (string literal only) & char \\
\end{tabular*} \\
\addlinespace
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}llll}
\multicolumn{2}{ c }{Integer Literals}  & \multicolumn{2}{ c }{Floating-Point Literals} \\
\cmidrule{1-2} \cmidrule{3-4}
Suffix   & Minimum Type & Suffix & Type \\
\cmidrule{1-1} \cmidrule{2-2} \cmidrule{3-3} \cmidrule{4-4}
u or U   & unsigned     & f or F & float \\
l or L   & long         & l or L & long double \\
ll or LL & long long    &        & \\
\end{tabular*} \\
\bottomrule
\end{tabular*}  
\end{table}

\end{document}

相关内容