
一言で言えば:
パッケージを使用している場合、左揃えの表のセル内で単語の折り返しを行うにはどうすればよいでしょうかbookstabs
?
私の問題の詳細:
私は、(うまくいけば)ACM マガジンに掲載される科学論文を書いています。ドキュメント クラスには、次のパッケージが含まれていますbooktabs
。https://ctan.org/pkg/booktabsスタイル ガイドでは他のテーブル スタイルの使用は許可されていません。
その前に、ドラフト文書で、パッケージを使用して次の表を作成しましたtabularray
。
\documentclass{article}
\usepackage{tabularray} % <-- line 2
\begin{document}
\begin{table}
\begin{tblr}{X[l]X[l]rrr} % <-- line 5
\hline
Authors/Editors & Title & Pages & Year & Ref. \\
\hline
David Salomon and Giovanni Motta &
Handbook of Data Compression & 1,370 & 2010 & [1] \\
Colt McAnlis and Aleks Haecky &
Understanding Compression: Data Compression
for Modern Developers & 241 & 2016 & [2] \\
\hline
\end{tblr} % <-- line 15
\end{table}
\end{document}
次の表が生成されます。
次に、使用する ACM テンプレートで試してみましたbooktabs
が、失敗しました。以下は、このパッケージを使用したサンプル コードです。2 行目、5 行目、15 行目のみが異なります (コメントでマークされています)。
\documentclass{article}
\usepackage{booktabs} % <-- line 2
\begin{document}
\begin{table}
\begin{tabular}{llrrr} % <-- line 5
\hline
Authors/Editors & Title & Pages & Year & Ref. \\
\hline
David Salomon and Giovanni Motta &
Handbook of Data Compression & 1,370 & 2010 & [1] \\
Colt McAnlis and Aleks Haecky &
Understanding Compression: Data Compression
for Modern Developers & 241 & 2016 & [2] \\
\hline
\end{tabular} % <-- line 15
\end{table}
\end{document}
結果は次のとおりです。
図2: パッケージで作成したテーブルbooktabs
とllrrr
単語の折り返しがなく、表が幅広すぎてページに収まりきりません。右側が切り取られています。
tabularray
を使用すると、左揃えの表セルで、パラメータX[l]
(行 5) を使用して単語の折り返しを指定できます。 でこれを実行すると、エラーbooktabs
メッセージ ("LaTeX エラー: 配列 arg に不正な文字があります") が表示され、表セルに単語の折り返しがなく、テキストが中央揃えになります。
図3: パッケージで作成したテーブルbooktabs
とX[l]X[l]rrr
X[l]
を に置き換えると、l
図 2 に示すような結果になります (エラーなし)。
の上https://ctan.org/pkg/booktabs18 ページにわたるパッケージのドキュメントですbooktabs
が、列幅、ワードラップ、または同様のトピックについてはどこにも触れられていません。実際、18 ページすべてで扱われているのは、水平線の太さという 1 つのトピックのみであり、あまり役に立ちません。
私の質問は次のとおりです:
最初の例に示したように、パッケージに対してワードラップ付きのテーブルを作成するには、何をしなければならないか教えてくださいbookstabs
。
答え1
問題は を使用することではなくbooktabs
、列の設定方法を指定していないことです。p{width}
複数のテキスト行を含む列に を使用します。
% booktabsprob.tex SE 640799
\documentclass{article}
\usepackage{booktabs} % <-- line 2
\begin{document}
\begin{table}
% \begin{tabular}{llrrr} % <-- line 5
\begin{tabular}{lp{4cm}rrr} % <-- line 5
\hline
Authors/Editors & Title & Pages & Year & Ref. \\
\hline
David Salomon and Giovanni Motta &
Handbook of Data Compression & 1,370 & 2010 & [1] \\
Colt McAnlis and Aleks Haecky &
Understanding Compression: Data Compression
for Modern Developers & 241 & 2016 & [2] \\
\hline
\end{tabular} % <-- line 15
\end{table}
\end{document}
答え2
およびtabularray
そのライブラリbooktabs
(booktabs
パッケージもロードします)を使用する場合:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs} % <---
\begin{document}
\begin{table}
\begin{tblr}{colsep = 4pt,
colspec = {@{} X[0.8,l]X[1.2,l]rrr @{}}
}
\toprule
Authors/Editors & Title & Pages & Year & Ref. \\
\midrule
David Salomon and Giovanni Motta
& Handbook of Data Compression
& 1,370 & 2010 & [1] \\
Colt McAnlis and Aleks Haecky
& Understanding Compression: Data Compression
for Modern Developers
& 241 & 2016 & [2] \\
\bottomrule
\end{tblr}
\end{table}
\end{document}
答え3
以下は、次の方法を使用した可能な解決策ですtabularx
。
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs} % <-- line 2
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{XXrrr} % <-- line 5
\toprule
Authors/Editors & Title & Pages & Year & Ref. \\
\midrule
David Salomon and Giovanni Motta &
Handbook of Data Compression & 1,370 & 2010 & [1] \\ \addlinespace
Colt McAnlis and Aleks Haecky &
Understanding Compression: Data Compression
for Modern Developers & 241 & 2016 & [2] \\
\bottomrule
\end{tabularx} % <-- line 15
\end{table}
\end{document}
答え4
あなたは尋ねました、
パッケージを使用している場合、左揃えのテーブルセルで [行の折り返し] を提供するにはどうすればよいですか
booktabs
?
自動行折り返しを有効にすることは、パッケージが提供する機能とはまったく異なりますbooktabs
。ご存知のとおり、l
列タイプでは自動行折り返しは提供されません。パッケージをロードし、の代わりにtabularx
その同名の環境を使用し、環境の全体の幅を に設定し、最初の 2 つの列にパッケージの列タイプを使用することをお勧めします。tabularx
tabular
tabularx
\textwidth
X
tabularx
@Bernardが追求したベースのアプローチと比較してこの答え、以下で追求するアプローチは、(a) 表の左端と右端の空白パディングを取り除き、(b) 列 1 と 2 のセルの内容を完全に揃えず、(c) 列 3 から 5 の内容を右揃えではなく中央揃えにし、(d)パッケージS
の列タイプを使用してsiunitx
、列 3 の数字を (暗黙の) 小数点マーカーに揃えます。
\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}
\usepackage{siunitx} % for S column type
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{@{}
LL
S[table-format=4.0,group-separator={,},group-minimum-digits=4]
cc @{}}
\toprule
Authors/Editors & Title & {Pages} & Year & Ref. \\
\midrule
David Salomon and Giovanni Motta &
Handbook of Data Compression & 1370 & 2010 & [1] \\
\addlinespace
Colt McAnlis and Aleks Haecky &
Understanding Compression: Data Compression
for Modern Developers & 241 & 2016 & [2] \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}