
下の図に示すように、表の行に色を付けても、@{}
サイドベアリングから色は削除されません。
色を削除するには、>{\kern-\tabcolsep}
下の図に示すように、 を使用して表の列にカーニングを適用します。
ただし、カーニングする列がp
- 列の場合、この方法は機能しません。代わりに、次に示すように、セルの内容が次のセルと揃わなくなります。
なぜですか? 何らかの方法で使用することは可能ですか\kern
(ゼロに設定すると同じ効果が得られることは知っています\tabcolsep
が、そうすると副作用があります)?
MWE:
\documentclass[table]{article}
\usepackage{lmodern, microtype, xcolor}
\begin{document}
\begin{tabular}{@{}lcr@{}}
\rowcolor{lightgray}test&test&test\\\hline
test&test&test\\
\rowcolor{lightgray}test&test&test\\
\end{tabular}
\vspace{1cm}
\begin{tabular}{>{\kern-\tabcolsep}lcr<{\kern-\tabcolsep}}
\rowcolor{lightgray}test&test&test\\\hline
test&test&test\\
\rowcolor{lightgray}test&test&test\\
\end{tabular}
\vspace{1cm}
\begin{tabular}{>{\kern-\tabcolsep}p{1cm}cr<{\kern-\tabcolsep}}
\rowcolor{lightgray}test&test&test\\\hline
test&test&test\\
\rowcolor{lightgray}test&test&test\\
\end{tabular}
\end{document}
答え1
固定幅の列の場合は、以下を追加\leavevmode
または使用できます\hskip
。
\documentclass[table]{article}
\usepackage{lmodern, microtype, xcolor}
\begin{document}
\begin{tabular}{@{}lcr@{}}
\rowcolor{lightgray}test&test&test\\\hline
test&test&test\\
\rowcolor{lightgray}test&test&test\\
\end{tabular}
\vspace{1cm}
\begin{tabular}{>{\kern-\tabcolsep}lcr<{\kern-\tabcolsep}}
\rowcolor{lightgray}test&test&test\\\hline
test&test&test\\
\rowcolor{lightgray}test&test&test\\
\end{tabular}
\vspace{1cm}
\begin{tabular}{>{\leavevmode\kern-\tabcolsep}p{1cm}cr<{\kern-\tabcolsep}}
\rowcolor{lightgray}test&test&test\\\hline
test&test&test\\
\rowcolor{lightgray}test&test&test\\
\end{tabular}
\vspace{1cm}
\begin{tabular}{>{\hskip-\tabcolsep}p{1cm}cr<{\kern-\tabcolsep}}
\rowcolor{lightgray}test&test&test\\\hline
test&test&test\\
\rowcolor{lightgray}test&test&test\\
\end{tabular}
\end{document}
追加した: 固定幅の列があり、セルに複数の行がある場合、最初の行のみに負のカーニングが適用されます。回避策としては、セルの内容を に含めることです\parbox[t]{\hsize}
(オプションは@Sveinung によって提案されました - ありがとうございます!)。環境を使用する場合、[t]
これは列タイプにも機能します。X
tabularx
L, R, C, J
の列タイプの場合、固定幅の列でない場合でも、最後の列に を追加(または を使用) するtabulary
必要があるようです。\leavevmode
\hskip