
我正在嘗試建立一個具有交替行顏色的表格,其中一種顏色稍微透明。我的表格佈局按預期工作,但是我無法找到使行顏色透明的方法。據我所知,該transparent
包將無法工作,因為它不能與 XeLaTeX 一起使用(我也在使用該fontspec
包,它需要 XeLaTeX)。以下是我迄今為止所擁有的 MWE
%!TEX program = xelatex
\documentclass[9pt,a4paper,twocolumn]{extbook}
\usepackage{xparse}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\NewDocumentEnvironment{rtable}{mm}%
{\rowcolors{2}{}{gray!50}\tabularx{\columnwidth}{c L}%
\bfseries{#1} & \bfseries{#2}\\%
}
{\endtabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}%
\begin{document}
\begin{rtable}{label 1}{label 2}
1 & this is a test\\
2 & to see if this works
\end{rtable}
\end{document}
產生以下結果:
但這顯然沒有透明度。完整的文檔有一個背景,我想透過行陰影顯示。雖然我知道它使使用透明度變得更容易,但我寧願避免使用 Tikzmatrix
包,因為這會打開一個完整的“另一個蠕蟲罐頭”,使表格單元格達到正確的大小。
答案1
您可以使用 tikz 命令,但由於透明度不尊重群組並且還會影響文本,因此涉及一定數量的設定和重置:
\documentclass[9pt,a4paper,twocolumn]{extbook}
\usepackage{xparse}
\usepackage[table]{xcolor}
\usepackage{tabularx,tikz}
\NewDocumentEnvironment{rtable}{mm}%
{\rowcolors{2}{}{gray!50}\tabularx{\columnwidth}{c L}%
\bfseries{#1} & \bfseries{#2}\\%
}
{\endtabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}%
\begin{document}
\begin{rtable}{label 1}{label 2}
1 & this is a test\\
2 & to see if this works
\end{rtable}
\begin{rtable}{label 1}{label 2}
\noalign{\pgfsetfillopacity{0.5}}%
\pgfsetfillopacity{1}%
1\pgfsetfillopacity{0.5}&
\leavevmode \pgfsetfillopacity{1}%
this is a test\\
2 & to see if this works
\end{rtable}
\end{document}