我之前在这里问过问题,并测试过最合适的答案之一,但仍然有一个错误,我无法找到解决方案。此外,表格仍然以一种我无法接受的方式分成两页。
最初我想复制这个表:
代码如下:
\documentclass[12pt]{report}
\usepackage{multirow}
\usepackage{xcolor}
\usepackage{booktabs}
\definecolor{cyan}{rgb}{0.9, 0.9, 0.98}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\usepackage{caption}
\usepackage{tabularx}
\usepackage{longtable}
\begin{document}
\centering
\refstepcounter{table}
\DefTblrTemplate{firsthead, middlehead,lasthead}{default}{} % <---
\DefTblrTemplate{contfoot-text}{normal}{\scriptsize\textit{Continued on the next page}}
\SetTblrTemplate{contfoot-text}{normal}
\begin{longtblr}[
label={table:1}
]{
colspec={|l l l},
colsep=6pt,
rows=5pt,
row{odd} = {bg=cyan},
row{1,2} = {bg=white},
row{2} = {rowsep=0pt},
row{3} = {font=\bfseries},
column{1} = {bg=white, colsep=3pt},
vline{1} = {abovepos = 1, belowpos = 1},
rowhead=3
}
& \SetCell[c=2]{c} \textbf{Table \thetable}. Parameters for protein solvation calculations using APBSmem. & \\
\cline[1.5pt]{2,3} & & \\[-6pt]
\cline[1.5pt]{2,3} & Parameter & Value \\
\cline[1.5pt,gray]{2,3} & Calculation type & Protein solvation \\
& Grid Dimensions & $\qtyproduct{289 x 289 x 257}{\angstrom}$ \\
& Coarse Grid Lengths & $\qtyproduct{202.889 x 202.915 x 185.759}{\angstrom}$ \\
& Fine Grid Lengths & $\qtyproduct{139.347 x 139.362 x 129.27}{\angstrom}$ \\
& Counter-Ions & 1.0, 0.154, 1.65 \\
& & $-1.0$, 0.154, 1.67 \\
& Protein Dielectric & 2.0 \\
& Solvent Dielectric & 80.0 \\
& Membrane Dielectric & 8.0 \\
& Headgroup Dielectric & 80.0 \\
& Boundary Conditions & Focus \\
& Solvent probe radius (srad) & 1.4 \\
& Surface sphere density (sdens) & 10 \\
& Temperature & 298.15 \\
& Z-position of membrane bottom & $-23.9$ \\
& Membrane thickness & 47.8 \\
& Headgroup thickness & -- \\
& Upper exclusion radius & 0 \\
& Lower exclusion radius & 0 \\
\cline[1.5pt]{2,3}
\end{longtblr}
\end{document}
得出下表:
问题如下:
Package xcolor Error: Undefined color belowpos
。- 标题:应为“表 1”,而不是“表 2”
- 它被分成了两页。我知道我的代码里有“下页继续”这句话,但是我一把它删掉,表格就变得乱七八糟了。
答案1
假设你喜欢将我的答案转换为table
浮点环境中的简单表格。这样做时,你应该考虑:
table
\refstepcounter{table}
增加标题编号,这样我的答案中表格开头和\addtocounter{table}{-1}
结尾的代码行就不再需要了。更糟糕的是,它们导致了你在问题中描述的问题。- 而不是
longtblr
使用talltblr
表格。
修正后,MWE 为:
\documentclass[12pt,reqno]{report}
\usepackage{pdfcomment}
\usepackage{textcomp}
\usepackage{xcolor}
\definecolor{lavender}{rgb}{0.9, 0.9, 0.98}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\usepackage[skip=1ex,
font=small,
labelfont=bf]{caption}
\usepackage{lipsum}
\begin{document}
\lipsum[66]
\begin{table}[ht]
\centering
\DefTblrTemplate{firsthead, middlehead,lasthead}{default}{} % <--- remoce caption generated by `talltblr`
\begin{talltblr}[
label={table:1}
]{
colspec={|l l X[l]},
colsep=6pt,
row{odd} = {bg=lavender},
row{1,2} = {bg=white},
row{2} = {rowsep=0pt},
row{3} = {font=\bfseries},
column{1} = {bg=white, colsep=3pt},
vline{1} = {abovepos = 1, belowpos = 1},
}
& \SetCell[c=2]{c} \textbf{Table \thetable}. Parameters for protein solvation calculations using APBSmem & \\
\cline[1.5pt]{2,3} & & \\[-6pt]
\cline[1.5pt]{2,3} & Parameter & Value \\
\cline[1.5pt,gray]{2,3} & Calculation type & Protein solvation \\
& Grid Dimensions & $\qtyproduct{289 x 289 x 257}{\angstrom}$ \\
& Coarse Grid Lengths & $\qtyproduct{202.889 x 202.915 x 185.759}{\angstrom}$ \\
& Fine Grid Lengths & $\qtyproduct{139.347 x 139.362 x 129.27}{\angstrom}$ \\
& Counter-Ions & 1.0, 0.154, 1.65 \\
& & $-1.0$, 0.154, 1.67 \\
& Protein Dielectric & 2.0 \\
& Solvent Dielectric & 80.0 \\
& Membrane Dielectric & 8.0 \\
& Headgroup Dielectric & 80.0 \\
& Boundary Conditions & Focus \\
& Solvent probe radius (srad) & 1.4 \\
& Surface sphere density (sdens) & 10 \\
& Temperature & 298.15 \\
& Z-position of membrane bottom & $-23.9$ \\
& Membrane thickness & 47.8 \\
& Headgroup thickness & -- \\
& Upper exclusion radius & 0 \\
& Lower exclusion radius & 0 \\
\cline[1.5pt]{2,3}
\end{talltblr}
\end{table}
\lipsum[66]
\begin{table}[ht]
\caption{The next table}
\label{table:2}
\begin{tblr}{hlines,vlines,
colspec={X[c]}
}
dummy table for test of caption numbering and referencing.
\end{tblr}
\end{table}
See table \ref{table:1} and \ref{table:2} ...
\end{document}
编译结果为:
编辑:
添加了用于测试表格编号和引用的虚拟表。建议的解决方案使用 tabularray
包 2022A 在我最近安装的 MiKTeX 上进行测试。编译结果如下,作为 MWE 正常工作的证明。
评论:
不幸的是,在 Overleaf 上编译仍然无法正常工作,因为他们仍然安装了“古老”版本的tabilarray
软件包,该版本尚未定义talltblr
。关于这个问题,最好的办法是向他们的团队寻求帮助,或者同时talltblr
使用longtblr
环境。