该表包含配方的成分,我想用灰色标记替换的成分。
覆盖的原因似乎是手动减少了列之间的空间@{\,}
。如果不使用,@{\,}
我不会遇到覆盖问题。我正在寻找一种方法来防止覆盖,或者另一种方法来最小化数量列中数字和单位之间的空间。这是我第一次尝试使用 siunitx 制作表格。欢迎提出任何建议,因为表格的代码在我看来很臃肿。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\usepackage{chemformula}
\begin{document}
\begin{table}[htb]
\begin{tabular}{l@{\,}l
S[table-format=3.2]
r@{\,}s[table-unit-alignment=left]
S[table-format=1.2e1,table-number-alignment=center] }
\toprule
\multicolumn{2}{c}{\multirow{3}{*}{Component}} & {\multirow{3}{*}{\shortstack{{Stock Solution} \\ (\si{\gram\per\liter}\ch{dH2O}) }}} &
\multicolumn{2}{c}{\multirow{3}{*}{Quantity}} &
{\multirow{3}{*}{\shortstack{Concentration in \\ Final Medium \\ (\si{\mole\per\liter})}}} \\ % multirow in S-Spalten mit Klammern schützen
\multicolumn{2}{l}{} & & \multicolumn{2}{l}{} & \\
\multicolumn{2}{l}{} & & \multicolumn{2}{l}{} & \\
\midrule
\addlinespace
(1) & NaCl & {---} & \tablenum[table-format=4.0]{23} & g & 12.34e-5 \\
\addlinespace
\rowcolor{gray} & A1 & 134.56 & & & 23.56e-7 \\
\rowcolor{gray} \multirow{-2}{*}{(2)} & A2 & 56.78 & {\multirow{-2}{*}{\tablenum[table-format=4.0]{1}}} & {\multirow{-2}{*}{mL}} & 56.47e-4 \\
\addlinespace
\multirow{2}{*}{(2)} & A2 & 56.78 & {\multirow{2}{*}{\tablenum[table-format=4.0]{1}}} & {\multirow{2}{*}{mL}} & 56.47e-4 \\
& A3 & 11.11 & & & 11.11e-1 \\
\addlinespace
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
以下是您可以使用 做的{NiceTabular}
事情nicematrix
。
请注意,您不需要\multirow
标题。
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{chemformula}
\usepackage{nicematrix}
\usepackage{makecell}
\NiceMatrixOptions{cell-space-top-limit = 2pt}
\begin{document}
\begin{table}[htb]
\begin{NiceTabular}{L@{\,}LS[table-format=3.2]R@{\,}L%
S[table-format=1.2e1,table-number-alignment=center]}%
[code-before = \rowcolor{lightgray}{3,4}]
\toprule
\multicolumn{2}{C}{Component}
&
{\makecell{{Stock Solution}\\ (\si{\gram\per\liter}\ch{dH2O)}} }
&
\multicolumn{2}{C}{Quantity}
&
{\makecell{Concentration in \\ Final Medium \\ (\si{\mole\per\liter})}}
\\
\midrule
\addlinespace
(1) & NaCl & {---} & \tablenum[table-format=4.0]{23} & g & 12.34e-5 \\[1mm]
\multirow{2}{*}{(2)} & A1 & 134.56 & {\multirow{2}{*}{\tablenum[table-format=4.0]{1}}} & {\multirow{2}{*}{mL}} & 23.56e-7 \\
& A2 & 56.78 & & & 56.47e-4 \\
\addlinespace
\multirow{2}{*}{(2)} & A2 & 56.78 & {\multirow{2}{*}{\tablenum[table-format=4.0]{1}}} & {\multirow{2}{*}{mL}} & 56.47e-4 \\
& A3 & 11.11 & & & 11.11e-1 \\
\addlinespace
\bottomrule
\end{NiceTabular}
\end{table}
\end{document}
您需要多次编译。
答案2
我建议采用以下解决方法:用包含相关单元格中的命令\multirow{3}{...}
的单一彩色行替换,并用 替换。无关:我用浅灰色替换了灰色,以使文本更易读。\Centerstack
stackengine
r@{\,}r
r>{\hskip-10pt}s
Gainsboro
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array}
\usepackage[table, svgnames]{xcolor}
\usepackage{siunitx}
\usepackage{chemformula}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{table}[htb]
\begin{tabular}{l@{\hskip 0.17em}l%
S[table-format=3.2]
r > {\hskip -11pt}s[table-unit-alignment=left]%
S[table-format=1.2e1,table-number-alignment=center] }
\toprule
\multicolumn{2}{c}{Component} & {\Centerstack{Stock Solution \\ (\si{\gram\per\liter} \ch{dH2O})}} &
\multicolumn{2}{c}{Quantity} & {\Centerstack{Concentration in \\ Final Medium \\ (\si{\mole\per\liter})}}
\\
\midrule
\addlinespace
(1) & NaCl & {---} & \tablenum[table-format=4.0]{23} & g & 12.34e-5 \\
\addlinespace
\rowcolor{Gainsboro} (2)) & \Centerstack{A1 \\ A2}& {\Centerstack[r]{134.56\\ 56.78}} & 1 & mL & {\Centerstack{\num{23.56e-7}\\\num{56.47e-4}}}\\
\addlinespace
\multirow{2}{*}{(2)} & A2 & 56.78 & {\multirow{2}{*}{\tablenum[table-format=4.0]{1}}} & {\multirow{2}{*}{mL}} & 56.47e-4 \\
& A3 & 11.11 & & & 11.11e-1 \\
\addlinespace
\bottomrule
\end{tabular}
\end{table}
\end{document}