\rowcolor 和 @{} 問題

\rowcolor 和 @{} 問題

在下一個範例中,我們可以看到它 \rowcolor沒有考慮序言@{}中的聲明tabular

在此輸入影像描述

這是正常行為嗎?有沒有一些優雅的方法來避免虛假的填充空間?

\documentclass{article}
\usepackage{xcolor, colortbl}

\begin{document}

\begin{tabular}{|c|c|c@{}|} 
\rowcolor{gray!30}
text & text & text
\end{tabular}

\end{document}

答案1

這可能會滿足您的要求

在此輸入影像描述

\documentclass{article}
\usepackage{xcolor, colortbl}

\begin{document}

\begin{tabular}{|c|c|>{\kern-\tabcolsep}c<{\kern-\tabcolsep}|} 
\rowcolor{gray!30}
text & text & text
\end{tabular}

\end{document}

答案2

nicematrix及其環境{NiceTabular}試圖解決包的問題colortbl

這是 的輸出{NiceTabular}

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}
\begin{NiceTabular}{|c|c|c@{}|}[colortbl-like]
\Hline
\rowcolor{gray!30}
text & text & text\\
\Hline
\end{NiceTabular}
\end{document}

你需要幾個編譯。

上述程式碼的輸出

答案3

您是否在尋找:

在此輸入影像描述

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}
    \begin{tabular}{|c|c| >{\columncolor{white}[\tabcolsep][0pt]}c @{}|}
\rowcolor{gray!30}
text & text & text
    \end{tabular}
\end{document}

相關內容