我现在正尝试在 overleaf 中设置一个表格,但在表格设置和视觉效果方面遇到困难。
我习惯使用 hlines 来设置表格,以在行之间添加差异,但是使用 \multirow 命令时似乎效果不太好。我以前从未遇到过这个问题,但不知何故,它没有考虑到这一点,而是将 h 线穿过多行。我找到了一个解决方案,即实施 clines 而不是 hlines,但我对结果并不完全满意,因为顶行的列边框比其下方的边框更粗。
关于如何实现相同但更优雅的表格设置,有什么建议吗?
谢谢!
\documentclass{article}{two sided}
\usepackage[version=4]{mhchem}
\usepackage{rotating}
\usepackage[table,xcdraw]{xcolor}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{diagbox}
\usepackage[acronym,nonumberlist]{glossaries}
\renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}}
\usepackage[scientific-notation = fixed, fixed-exponent = 0,per-mode=symbol]{siunitx}
\sisetup{detect-all}
\usepackage{wrapfig}
\usepackage{longtable}
\usepackage{float}
\usepackage{pdfpages}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{siunitx}
\begin{document}
\begin{table}[H]
\centering
\caption{Flux (\emph{J}) }
\label{tab:4.4.1}
\begin{tabular}{|l|l|l|l|l|l|l|ll}
\multirow{2}{*}{\begin{tabular}[l]{@{}l@{}} \textbf{energy}\\ \textbf{density (cm\textsuperscript{2}/MW)}\end{tabular}} &
\multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{1064 }\end{tabular}} &
\multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{532 } \end{tabular}}
& \multicolumn{2}{|l|}{\begin{tabular}[l]{@{}l@{}} \textbf{355 }\end{tabular}} \\ \hline
& \textbf{Volume ($\mu$L)} & \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} & \textbf{Volume ($\mu$L)} &\textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} &\textbf{Volume ($\mu$L)} & \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} \\ \hline
10 & $\pm$ & $\pm$ & $\pm$ & & & \\
25 & $\pm$ & $\pm$ & $\pm$ & & & \\
50 & $\pm$ & $\pm$ & $\pm$ & & & \\
70 & $\pm$ & $\pm$ & $\pm$ & & & \\
100 & $\pm$ & $\pm$ & $\pm$ & & & \\
\end{tabular}
\end{table}
\begin{table}[H]
\centering
\caption{flux (\emph{J}) }
\label{tab:4.4.2}
\begin{tabular}{|l|l|l|l|l|l|l|ll}
\multirow{2}{*}{\begin{tabular}[l]{@{}l@{}} \textbf{energy}\\ \textbf{density (cm\textsuperscript{2}/MW)}\end{tabular}} &
\multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{1064 }\end{tabular}} &
\multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{532 } \end{tabular}}
& \multicolumn{2}{|l|}{\begin{tabular}[l]{@{}l@{}} \textbf{355 }\end{tabular}} \\ \cline{2-7}
& \textbf{Volume ($\mu$L)} & \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} & \textbf{Volume ($\mu$L)} &\textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} &\textbf{Volume ($\mu$L)} & \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} \\ \hline
10 & $\pm$ & $\pm$ & $\pm$ & & & \\
25 & $\pm$ & $\pm$ & $\pm$ & & & \\
50 & $\pm$ & $\pm$ & $\pm$ & & & \\
70 & $\pm$ & $\pm$ & $\pm$ & & & \\
100 & $\pm$ & $\pm$ & $\pm$ & & & \\
\end{tabular}
\end{table}
\end{document}
答案1
作为(题外话)补充@js 比布拉很好的回答(+1):
- 对于单位使用
siunitx
包 - 用于表格
tabular*
环境,自动计算\tabcolsep
距离 \NewExpandableDocumentCommand
对于多列单元格,由缩短定义\mcc
- 删除了表中的所有杂乱内容(嵌套的
tabular
s)
\documentclass{article}
\usepackage{booktabs, makecell, multirow}
\renewcommand\theadfont{\bfseries\normalsize}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c}{#2}}
\usepackage{siunitx}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[ht]
\caption{Flux ($J$) }
\label{tab:4.4.1}
% \sisetup{per-mode = symbol}
\small
\setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
S[table-format=3.0]
*{6}{>{$}c<{$}}
}
\toprule
{\multirow{3}{*}{\thead{energy\\ density\\
(\si{\centi\metre\squared\per\mega\watt})}}}
& \mcc[2]{\thead{1064}}
& \mcc[2]{\thead{532}}
& \mcc[2]{\thead{355}} \\
\cmidrule(r){2-3}\cmidrule(r){4-5}\cmidrule{6-7}
& $\thead{Volume\\ (\si{\micro\litre})}$
& $\thead{$J$\\ (\si{\per\micro\liter\per\hour})}$
& $\thead{Volume\\ (\si{\micro\liter})}$
& $\thead{$J$\\ (\si{\per\micro\liter\per\hour})}$
& $\thead{Volume\\ (\si{\micro\liter})}$
& $\thead{$J$\\ (\si{\per\micro\liter\per\hour})}$ \\
\midrule
10 & \pm & \pm & \pm & & & \\
25 & \pm & \pm & \pm & & & \\
50 & \pm & \pm & \pm & & & \\
70 & \pm & \pm & \pm & & & \\
100 & \pm & \pm & \pm & & & \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
(红线表示文字边框)
答案2
\documentclass{article}
\usepackage{ multirow,makecell, booktabs}
%
\begin{document}
\begin{table}
\caption{Flux (\emph{J}) }
\label{tab:4.4.1}
\noindent\hspace{-2cm}
\begin{tabular}{*9{c}}\toprule
&\multicolumn{2}{c}{ \begin{tabular}[l]{@{}l@{}} \textbf{1064 }\end{tabular}}
&\multicolumn{2}{c}{ \begin{tabular}[l]{@{}l@{}} \textbf{532 } \end{tabular}}
&\multicolumn{2}{c}{\begin{tabular}[l]{@{}l@{}} \textbf{355 }\end{tabular}} \\ \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}
\multicolumn{1}{c}{\makecell[c]{\textbf{energy density} \\\textbf{(cm\textsuperscript{2}/MW)}}}
& \makecell[c]{\textbf{Volume}\\ \textbf{($\mu$L)}}
& \makecell[c]{\textbf{\emph{J}}\\ \textbf{ ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}}
&\makecell[c]{\textbf{Volume} \\\textbf{($\mu$L)}}&\makecell[c]{\textbf{\emph{J}} \\\textbf{($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}} &\makecell[c]{\textbf{Volume}\\\textbf{ ($\mu$L)}}& \makecell[c]{\textbf{\emph{J}} \\\textbf{($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}} \\ \midrule
10 & $\pm$ & $\pm$ & $\pm$ & & & \\
25 & $\pm$ & $\pm$ & $\pm$ & & & \\
50 & $\pm$ & $\pm$ & $\pm$ & & & \\
70 & $\pm$ & $\pm$ & $\pm$ & & & \\
100 & $\pm$ & $\pm$ & $\pm$ & & & \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
您也可以直接使用multicolumn
来完成它。
\documentclass{article}
\usepackage{float}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\begin{table}[H]
\centering
\caption{Flux (\emph{J}) }
\label{tab:4.4.1}
\begin{tabular}{@{}ccccccc@{}}
\toprule
& \multicolumn{2}{c}{\textbf{1064}} & \multicolumn{2}{c}{\textbf{532}} & \multicolumn{2}{c}{\textbf{355}} \\ \midrule
$\boldsymbol{\rho}$ & $\boldsymbol{V}$ & $\boldsymbol{J}$ & $\boldsymbol{V}$ & $\boldsymbol{J}$ & $\boldsymbol{V}$ & $\boldsymbol{J}$ \\
$\boldsymbol{(cm^2 {MW}^{-1})}$ & $\boldsymbol{(\mu L)}$ & $\boldsymbol{({\mu L}^{-1} h^{-1})}$ & $\boldsymbol{(\mu L)}$ & $\boldsymbol{({\mu L}^{-1} h^{-1})}$ & $\boldsymbol{(\mu L)}$ & $\boldsymbol{({\mu L}^{-1} h^{-1})}$ \\ \midrule
10 & $\pm$ & $\pm$ & $\pm$ & & & \\
25 & $\pm$ & $\pm$ & $\pm$ & & & \\
50 & $\pm$ & $\pm$ & $\pm$ & & & \\
70 & $\pm$ & $\pm$ & $\pm$ & & & \\
100 & $\pm$ & $\pm$ & $\pm$ & & & \\ \midrule
\multicolumn{7}{l}{$\boldsymbol{\rho}$ ... energy density; $\boldsymbol{V}$ ... volume; $\boldsymbol{J}$ ... flux} \\ \bottomrule
\end{tabular}
\end{table}