
如果您對表格中的一行進行著色,@{}
則不會刪除側軸承上的顏色,如下圖所示。
若要刪除顏色,您可以使用 直接在表格列中進行緊排>{\kern-\tabcolsep}
,如下圖所示:
但是,如果您要緊排的列是 - 列,則此方法不起作用p
。相反,單元格內容不再與下一個單元格對齊,如下所示:
為什麼?是否可以\kern
以某種方式使用(我知道設置\tabcolsep
為零可能會產生相同的效果,但這樣做會產生一些副作用)?
微量元素:
\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}
添加:如果您有固定寬度的列,如果儲存格有多行,則只有第一行具有負字距調整。解決方法包括將單元格內容包含在 a 中\parbox[t]{\hsize}
([t]
@Sveinung 建議選擇該選項 - 謝謝!)。X
如果您使用環境,這也適用於列類型tabularx
。
對於L, R, C, J
中的列類型tabulary
,似乎您還必須為最後一列添加\leavevmode
(或使用\hskip
),即使它不是固定寬度列。