我想在 LaTeX、overleaf 中制作类似的表格(见下图)。我阅读了在 overleaf 中创建表格的文档,但它似乎无法制作相同的表格...有什么想法我该怎么做吗?
这是我的完整代码:
\documentclass[12pt,reqno]{report}
\usepackage{amsmath,amssymb}
\usepackage{siunitx}
\usepackage{xcolor,colortbl}
\definecolor{lavender}{rgb}{0.9, 0.9, 0.98}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{35pt}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{pdfcomment}
\usepackage{textcomp}
\DeclareSIUnit\angstrom{\text {Å}}
\ifdefined\qtyproduct\else
\NewCommandCopy\qtyproduct\SI
\fi
\usepackage{empheq}
\usepackage{tabularx}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{1em}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.5}
\usepackage[style=numeric, sorting=none]{biblatex}
\addbibresource{library.bib}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[rightcaption]{sidecap}
\usepackage{graphicx} %package to manage images
\graphicspath{ {images/} }
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\usepackage{graphicx}
\graphicspath{ {./figs/} }
\usepackage{microtype}
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\counterwithout{equation}{section}
\makeatletter
\newcommand*\bigcdot{\mathpalette\bigcdot@{.5}}
\newcommand*\bigcdot@[2]{\mathbin{\vcenter{\hbox{\scalebox{#2}{$\m@th#1\bullet$}}}}}
\makeatother
\begin{table}[]
\caption{Parameters for protein solvation calculations using APBSmem}
\centering
\begin{tabular}{ll}
\toprule
Parameter & Value \\
\midrule
\rowcolor{cyan}
Calculation type & Protein solvation \\
Grid Dimensions & $\qtyproduct{289 x 289 x 257}{\angstrom}$ \\
\rowcolor{cyan}
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}$ \\
\rowcolor{cyan}
Counter-Ions & 1.0, 0.154, 1.65 \\
& -1.0, 0.154, 1.67 \\
\rowcolor{cyan}
Protein Dielectric & 2.0 \\
Solvent Dielectric & 80.0 \\
\rowcolor{cyan}
Membrane Dielectric & 8.0 \\
Headgroup Dielectric & 80.0 \\
\rowcolor{cyan}
Boundary Conditions & Focus \\
Solvent probe radius (srad) & 1.4 \\
\rowcolor{cyan}
Surface sphere density (sdens) & 10 \\
Temperature & 298.15 \\
\rowcolor{cyan}
Z-position of membrane bottom & -23.9 \\
Membrane thickness & 47.8 \\
\rowcolor{cyan}
Headgroup thickness & -- \\
Upper exclusion radius & 0 \\
\rowcolor{cyan}
Lower exclusion radius & 0 \\
\bottomrule
\end{tabular}
\label{table:1}
\end{table}
下面是生成的表格,我想做些改变:1)将表 1 的标题设为粗体,但使用 \textbf 并不是一件容易的事情,因为它会使标题加倍……
正如您在图片中看到的,“39”是页码,因为表格太长,有什么想法可以解决这个问题吗?
在左侧添加一条相同粗细的线(如图 1 所示)
答案1
这是我尝试使用tabularray 包,我推荐用于任何复杂的表格。
它非常接近;不过我按照你的指示使用了青色行而不是灰色。(稍微柔和一点,因为你的太亮了,不符合我的口味。)如果你愿意,很容易把它们变成灰色。
如果表格足够大以至于可能跨越页面,我根本不会使用表格环境(浮动)。
该包有自己的方法,可以在表格上方插入标题并在每页上重复显示,但这个特定的表格有一个问题,即您希望将标题包含在表格内,以便表格的左边框包含它。因此,我没有使用该包的功能,而是隐藏了通常的标题,然后手动增加表格计数器,然后将其重置。这不是很优雅,也许有人能想到更好的方法。
由于它是 longtblr,因此它应该可以很好地跨越多个页面(而不会与页脚重叠)。它甚至会重复标题行。请参阅包装文档了解更多信息。
(我删除了所有与问题无关的内容。但是,请注意,您在当前文档中加载了两次 xcolor。不要这样做。)
我插入了大量评论,以便您可以看到每件事的作用,并在必要时进行调整。
编辑:如果您希望表格能够跨越多页,以下是我的建议。如果您想将其压缩到一页,我在下面提出了另一个建议。
\documentclass[12pt]{report}
\renewcommand{\familydefault}{\sfdefault}% sans serif font
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
% suppress normal caption as we will use a caption row instead
\DefTblrTemplate{caption}{default}{}
\DefTblrTemplate{capcont}{default}{}
% increase table counter for caption inside row; add label
\noindent\refstepcounter{table}\label{table:1}%
\begin{longtblr}{
colspec={|[2pt]% two point line on left border of table
@{\kern0pt}% small whitespace after that line
Q[l,colsep=0pt,rightsep=4em]% first column, left aligned,
% no space on left, large space on right
Q[l,colsep=0pt]},% second column, left aligned, no space on left
rowhead=3,% first three rows are header and should be repeated
% if the table spans pages
row{1} = {abovesep=2ex,belowsep=2ex},% extra vertical space 1st row
row{2} = {abovesep=0.5ex,belowsep=0.5ex},% blank row #2
row{3} = {abovesep=1.5ex,belowsep=1.5ex,preto={\bfseries}},% row 3
% has some extra space and text in it is bold
row{4-Z} = {abovesep=0.8ex,belowsep=0.4ex},% remainder of rows have
% a little extra vertical space
row{even[4-Z]} = {cyan!40!white},% even rows 4-on have cyan background
% use, e.g., black!40!white for gray
hline{2} = {2pt}, % 2 point horizontal line above row 2
hline{2} = {1}{1}{leftpos=-0.2}, % a little gap on the left of that line
hline{3} = {1pt}, % thinner line above row 3
hline{3} = {1}{1}{leftpos=-0.2}, % also has a small gap on left
hline{4} = {0.7pt},% even thinner line above row 4
hline{4} = {1}{1}{leftpos=-0.2},% also has a small gap on left
hline{Z} = {1.5pt},% medium line at bottom of table
hline{Z} = {1}{1}{leftpos=-0.2}% small gap on left
}
% the first cell is the caption cell, spans two olumns
\SetCell[c=2]{c}\textbf{Table \thetable.} Parameters for protein solvation calculations using APBSmem. & \\
& \\ % empty row
Parameter & Value \\ % header row
Calculation type & Protein solvation \\
Grid Dimensions & 289 $\times$ 289 $\times$ 257 \\
Coarse Grid Lengths & 202.889 $\times$ 202.915 $\times$ 185.759 \\
Fine Grid Lengths & 139.347 $\times$ 139.362 $\times$ 129.27 \\
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
\end{longtblr}
% undo extra increase to table counter
\addtocounter{table}{-1}
\end{document}
编辑:如果你不想让它跨越多个页面,那么你应该使用浮点数,即一个table
环境,然后在里面使用更简单的tblr
环境而不是。longtblr
确保[h!tb]
对浮点数使用位置说明符(此处),因为在示例代码中没有这样做。
您仍需要手动添加标题并增加计数器以将其保留在表格内。但是,由于环境tblr
不会自行增加表格计数器,因此您无需在最后重置它。
这是代码。
\documentclass[12pt]{report}
\renewcommand{\familydefault}{\sfdefault}% sans serif font
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{lipsum}
\begin{document}
\begin{table}[h!tb]
% increase table counter for caption inside row; add label
\noindent\refstepcounter{table}\label{table:1}
\begin{tblr}{
colspec={|[2pt]% two point line on left border of table
@{\kern0pt}% small whitespace after that line
Q[l,colsep=0pt,rightsep=4em]% first column, left aligned,
% no space on left, large space on right
Q[l,colsep=0pt]},% second column, left aligned, no space on left
row{1} = {abovesep=2ex,belowsep=2ex},% extra vertical space 1st row
row{2} = {abovesep=0.5ex,belowsep=0.5ex},% blank row #2
row{3} = {abovesep=1.5ex,belowsep=1.5ex,preto={\bfseries}},% row 3
% has some extra space and text in it is bold
row{4-Z} = {abovesep=0.8ex,belowsep=0.4ex},% remainder of rows have
% a little extra vertical space
row{even[4-Z]} = {cyan!40!white},% even rows 4-on have cyan background
% use, e.g., black!40!white for gray
hline{2} = {2pt}, % 2 point horizontal line above row 2
hline{2} = {1}{1}{leftpos=-0.2}, % a little gap on the left of that line
hline{3} = {1pt}, % thinner line above row 3
hline{3} = {1}{1}{leftpos=-0.2}, % also has a small gap on left
hline{4} = {0.7pt},% even thinner line above row 4
hline{4} = {1}{1}{leftpos=-0.2},% also has a small gap on left
hline{Z} = {1.5pt},% medium line at bottom of table
hline{Z} = {1}{1}{leftpos=-0.2}% small gap on left
}
% the first cell is the caption cell, spans two olumns
\SetCell[c=2]{c}\textbf{Table \thetable.} Parameters for protein solvation calculations using APBSmem. & \\
& \\ % empty row
Parameter & Value \\ % header row
Calculation type & Protein solvation \\
Grid Dimensions & 289 $\times$ 289 $\times$ 257 \\
Coarse Grid Lengths & 202.889 $\times$ 202.915 $\times$ 185.759 \\
Fine Grid Lengths & 139.347 $\times$ 139.362 $\times$ 129.27 \\
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
\end{tblr}
\end{table}
\end{document}
(输出结果应该与上面的差不多,只是仅限于一页。)