%20%E3%81%8C%E6%8C%87%E5%AE%9A%E3%82%88%E3%82%8A%E3%82%82%E5%B9%85%E3%81%8C%E5%BA%83%E3%81%84%E3%81%AE%E3%81%AF%E3%81%AA%E3%81%9C%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
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
のX
列タイプを使用すると、テキスト幅とまったく同じ幅で、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}