7 列の tabular(x) が指定よりも幅が広いのはなぜですか?

7 列の tabular(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

最初のバージョン:tabularxX列タイプを使用すると、テキスト幅とまったく同じ幅で、7 つの同じ幅の列で構成されるテーブルが作成されます。列を左揃えにするために、>{\raggedright\arraybackslash}新しいカスタム列タイプ を使用して定義しましたL

2 番目のバージョン: ここでは、各列の内容の左右に追加される値を考慮して、列の幅を手動で計算しました\tabcolsep。ご覧のとおり、結果の表は予想どおり、テキスト幅よりもわずかに狭くなります。

3 番目のバージョン: このバージョンでは、テーブルの幅がテキスト幅と同じになるように、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}

 

関連情報