さまざまなテーブル パッケージを試しているうちに、各パッケージは基本的に独自のものであり、他の優れたパッケージとの互換性に欠けていることがよくあることに気付きました。
そこで、 -パッケージのスタイルbooktabs
(水平線のみ)で、 -パッケージの機能makecell
(\thead
、 、...)と行に色を付ける機能( ではあまり直感的ではないが、議論したように)を備えた表を\makegapedcells
作成しようとしました。booktabs
ここ。
さまざまなテーブル構成を少し比較してみました。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[skip=10pt]{parskip}
\usepackage[table]{xcolor}
\usepackage{rotating}
\usepackage{array}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage[column=Q]{cellspace} % changed to Q for simultaneous use of siunitx
\newcommand{\tableComment}[2]{
\begin{tabular}{m{4.5cm}}
#1\\[5pt]#2
\end{tabular}}
\renewcommand{\theadfont}{\itshape}
\renewcommand{\theadgape}{}
\renewcommand{\theadalign}{cc}
\setcellgapes{1pt}
\renewcommand{\cellrotangle}{90}
\newcommand{\TopRule}{\Xhline{1pt}}
\newcommand{\MidRule}{\Xhline{.5pt}}
\newcommand{\BottomRule}{\Xhline{1pt}}
\begin{document}
\tableComment{1: Standard Lines, Head with \texttt{makecell}, no additional spacing}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\hline
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \hline
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \hline
\end{tabular}
}
\tableComment{2: Standard Lines, Head with \texttt{makecell}, spacing with \texttt{cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\hline
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \hline
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \hline
\end{tabular}
}
\tableComment{3: Lines with \texttt{Xhline}, Head with \texttt{makecell}, spacing with \texttt{cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}\\
\tableComment{4: Lines with \texttt{Xhline}, Head with \texttt{thead}, spacing with \texttt{makegapedcells}}
{
\rowcolors{1}{gray!20}{white}
\makegapedcells
\begin{tabular}{ll}\TopRule
\rowcolor{gray!40}
\thead{My Head} & \thead{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\tableComment{5: Lines with \texttt{booktabs}, Head with \texttt{makecell}, spacing with \texttt{booktabs}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\toprule
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \midrule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \bottomrule
\end{tabular}
}
\tableComment{6: Lines with \texttt{Xhline}, Head with \texttt{thead}, spacing with \texttt{cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
\thead{My Head} & \thead{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\settowidth\rotheadsize{\theadfont second}
\tableComment{7: Lines with \texttt{Xhline}, Head with \texttt{rothead}, spacing with \texttt{callspace} }
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\tableComment{8: Lines with \texttt{booktabs}, Head with \texttt{rothead}, spacing with \texttt{booktabs}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\toprule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\\midrule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \bottomrule
\end{tabular}
}
\tableComment{9: Lines with \texttt{Xhline}, Head with \texttt{rothead}, spacing with \texttt{makegapedcells}}
{
\rowcolors{1}{gray!20}{white}
\makegapedcells
\begin{tabular}{ll}\TopRule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\end{document}
ご覧のとおり、パッケージのほぼすべての組み合わせに何らかの問題があります (または単に見栄えがよくありません)。私のお気に入りはバージョン 3 と 6 です。
しかし、回転したセルや、\makegapedcells
ブックタブ スタイルで色付きの表を作成するにはどうすればよいでしょうか? (また、booktabs
新しい水平線を導入して垂直スペースを変更する以外に、 -package は実際に何を行うのでしょうか?)。また、\makegapedcells
の内部を除くすべての色を削除するのはなぜでしょうか\thead
?
答え1
セル内の垂直間隔に関しては、cellspace
正しい方法で使用すると勝者は… (ドラムロール) … です。セルの上部と下部の最小間隔の値を指定するのを忘れただけです。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[skip=10pt]{parskip}
\usepackage[table]{xcolor}
\usepackage{rotating}
\usepackage{array}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage[column=Q]{cellspace} % changed to Q for simultaneous use of siunitx
\setlength{\cellspacetoplimit}{5pt}
\setlength{\cellspacebottomlimit}{5pt}
\newcommand{\tableComment}[2]{
\begin{tabular}{m{4.5cm}}
#1\\[5pt]#2
\end{tabular}}
\renewcommand{\theadfont}{\itshape}
\renewcommand{\theadgape}{}
\renewcommand{\theadalign}{cc}
\setcellgapes{1pt}
\renewcommand{\cellrotangle}{90}
\newcommand{\TopRule}{\Xhline{1pt}}
\newcommand{\MidRule}{\Xhline{.5pt}}
\newcommand{\BottomRule}{\Xhline{1pt}}
\begin{document}
\tableComment{1: Standard Lines, Head with \texttt{makecell}, no additional spacing}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\hline
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \hline
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \hline
\end{tabular}
}
\tableComment{2: Standard Lines, Head with \texttt{makecell}, spacing with \texttt{\color{red}cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\hline
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \hline
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \hline
\end{tabular}
}
\tableComment{3: Lines with \texttt{Xhline}, Head with \texttt{makecell}, spacing with \texttt{\color{red}cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}\\
\tableComment{4: Lines with \texttt{Xhline}, Head with \texttt{thead}, spacing with \texttt{makegapedcells}}
{
\rowcolors{1}{gray!20}{white}
\makegapedcells
\begin{tabular}{ll}\TopRule
\rowcolor{gray!40}
\thead{My Head} & \thead{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\tableComment{5: Lines with \texttt{booktabs}, Head with \texttt{makecell}, spacing with \texttt{booktabs}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\toprule
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \midrule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \bottomrule
\end{tabular}
}
\tableComment{6: Lines with \texttt{Xhline}, Head with \texttt{thead}, spacing with \texttt{\color{red}cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
\thead{My Head} & \thead{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\settowidth\rotheadsize{\theadfont second}
\tableComment{7: Lines with \texttt{Xhline}, Head with \texttt{rothead}, spacing with \texttt{\color{red}cellspace} }
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\tableComment{8: Lines with \texttt{booktabs}, Head with \texttt{rothead}, spacing with \texttt{booktabs}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\toprule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\\midrule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \bottomrule
\end{tabular}
}
\tableComment{9: Lines with \texttt{Xhline}, Head with \texttt{rothead}, spacing with \texttt{makegapedcells}}
{
\rowcolors{1}{gray!20}{white}
\makegapedcells
\begin{tabular}{ll}\TopRule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\end{document}
答え2
残念ながら、cellspace
セルの内容によっては行の高さが不均一になる場合があります。すべてのパッケージで、色がルールを上書きするため、ブラウザでルールが消えるという問題が発生します。
その包みcals実際のところ、ほとんどの問題を克服できる唯一のパッケージだと私は思います。
もう 1 つの可能性は、表 ( \tabcolsep{0pt}
arraystretch > 1
) 内のセル間のスペースをすべてキャンセルし、狭い列を使用して列間にスペースを追加し、行と同じ色の太い水平線と (最終的には) 狭い黒の を組み合わせて行間にスペースを追加することですarrayrulesep
。
次に、鉛の支柱を使用して列と行の間隔を空けていた、表形式の古い植字方法を模倣します。
[いくつか例を挙げるつもりですが、コマンドの副作用に遭遇したので、まず質問する必要があります。]
答え3
nicematrix
(≥ 5.6)かつ の場合booktabs
、次の結果が直接得られます。
\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\begin{document}
\begin{NiceTabular}{ll}[cell-space-limits=1pt]
\CodeBefore
\rowcolor{gray!40}{1}
\rowcolors{2}{gray!20}{}
\Body
\toprule
My Head & \Block{}<\rotate>{My second\\ Head} \\
\midrule
some content & $\dfrac{1}{2}$ \\
foo & bar \\
\bottomrule
\end{NiceTabular}
\end{document}
コマンド\toprule
、midrule
、 は\bottomrule
によって提供されますbooktabs
。\Block
また\rotate
は によって提供されますnicematrix
。キーワード\CodeBefore
およびと (および)\Body
内のコマンドはによって提供されます。パッケージはロードされていません。ロードしても同じ結果になる可能性があります。\rowcolor
\rowcolors
nicematrix
colortbl