為什麼我的 7 列表格 (x) 比指定的寬?

為什麼我的 7 列表格 (x) 比指定的寬?

我想要一個非常簡單的表(tabular/x/*隨便什麼),有 7 列,每列佔 14% \linewidth,總共 98%。

但由於某些原因,最右邊的列 a) 在邊距上,b) 在表格規則之外。 在此輸入影像描述

我如何解決它?

\documentclass[version=last,12pt]{scrreport}
\usepackage{tabularx,booktabs}

\begin{document}
\begin{table}[t]
\tiny
\begin{tabularx}{\linewidth}{@{}
p{0.14\linewidth}
p{0.14\linewidth}
p{0.14\linewidth}
p{0.14\linewidth}
p{0.14\linewidth}
p{0.14\linewidth}
p{0.14\linewidth}
@{}
}
\toprule
Excavator
& Alphanumeric data 
& Location 
& Warranty details 
& Expiry date of the support period 
& Required business properties
& Maximum needed diesel
\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}     

答案1

第一個版本:使用tabularx's Xtype columns 會產生一個與 textwidth 一樣寬的表,並由 7 個同樣寬的列組成。為了使列左對齊,我使用>{\raggedright\arraybackslash}並定義了一個新的自訂列類型L

第二個版本:在這裡,我手動計算了列寬,考慮了\tabcolsep新增到每列內容左側和右側的值。正如您所看到的,正如預期的那樣,生成的表格比文字寬度稍窄。

第三個版本:在這個版本中,我tabular*結合使用來\extracolsep{\fill}}確保表格與文字寬度一樣寬。

以下螢幕截圖中的垂直線是由showframe套件引起的,顯示了文字寬度/邊距的開頭。

在此輸入影像描述

附註:我希望\tiny本範例中僅使用了字體大小。由於這個字體太小,很難閱讀,我建議不要使用它。即使使用常規字體大小,您也可以輕鬆地將表格放入文字寬度中,從而產生類似於

在此輸入影像描述

根據表格的內容,允許不同的列寬也可能是有益的。

\documentclass[version=last,12pt]{scrreport}
\usepackage{tabularx,booktabs}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\newcolumntype{Z}[2]{>{\raggedright\arraybackslash}p{\dimexpr #1\textwidth- #2\tabcolsep} }

\newcolumntype{Y}[1]{>{\raggedright\arraybackslash}p{\dimexpr #1\textwidth} }

\usepackage{showframe}
\begin{document}
\begin{table}[t]
\tiny
\begin{tabularx}{\linewidth}{@{}*{7}{L}@{}}
\toprule
Excavator
& Alphanumeric data 
& Location 
& Warranty details 
& Expiry date of the support period 
& Required business properties
& Maximum needed diesel
\\
\bottomrule
\end{tabularx}
\end{table}


\begin{table}[t]
\tiny
\begin{tabular}{@{}Z{0.14}{1} 
                   *{5}{Z{0.14}{2}}
                   Z{0.14}{1} @{}}
\toprule
Excavator
& Alphanumeric data 
& Location 
& Warranty details 
& Expiry date of the support period 
& Required business properties
& Maximum needed diesel
\\
\bottomrule
\end{tabular}
\end{table}


\begin{table}[t]
\tiny \setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{7}{Y{0.14}}}
\toprule
Excavator
& Alphanumeric data 
& Location 
& Warranty details 
& Expiry date of the support period 
& Required business properties
& Maximum needed diesel
\\
\bottomrule
\end{tabular*}
\end{table}

\end{document}

 

相關內容