我已经使用以下代码创建了一个表:
\documentclass[a4paper, oneside]{article}
\usepackage{caption}
\usepackage{tabulary}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{ragged2e}
\usepackage{geometry}
\usepackage{siunitx}
\sisetup{per-mode=symbol}
\DeclareSIUnit \annum{a}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{c
c
c
c
S[table-format=3]
S[table-format=3.1]
S[table-format=3.1]
S[table-format=1.3]
S[table-format=3.1]
S[table-format=1.4]
S[table-format=2.2]
}
\toprule
\makecell{Reservoir\\ (Location)}
& \makecell{Dam/SBT \\ Commissioning \\ year}
& \makecell{SBT \\ Type \\ (A/B)}
& \makecell{SBT \\ length \\ {[\si{\metre}]}}
& \makecell{$Q_d$ \\ {[\si{\cubic\metre\per\second}]}}
& \makecell{$t_{op}$ \\ {[\si{\day\per\annum}]}}
& \makecell{$V_{s,m,\mathrm{out}}$ \\ {[\SI{E3}{\cubic\metre\per\annum}]}}
& \makecell{$\sigma_{s,m}$ \\ {[\si{\mL\per\L}]}}
& \makecell{MAS \\ {[\SI{E3}{\cubic\m\per\annum}]}}
& \multicolumn{2}{c}{\makecell{Bypassing\\ efficiencies $\eta_{b}$ }} \\
\cmidrule{10-11}
& & & & & & & & & {$\eta_{\sigma}$} {[\si{\percent}]} & {$\eta_v$} {[\si{\percent}]}\\
\midrule
Asahi (JP) & 1987/1998 & A & 2384 & 140 & 14.5 & 65.0 & 0.371 & 109.4 & 0.0371 & 59.43 \\
Miwa (JP) & 1952/2004 & B & 4308 & 300 & 2.5 & 400.0 & 6.173 & 685.0 & 0.6173 & 58.39 \\
Palagnedra (CH) & 1952/1974 & A & 1760 & 250 & 5.0 & 92.0 & 0.852 & 200.0 & 0.0852 & 46.00 \\
Pfaffensprung (CH) & 1921/1922 & ns & 280 & 220 & 150.0 & 94.0 & 0.033 & 100.0 & 0.0033 & 94.00 \\
Rempen (CH) & 1924/1983 & A & 450 & 80 & 3.0 & 4.0 & 0.193 & ns & 0.0193 & ns \\
Runcahez (CH) & 1961/1961 & A & 572 & 56 & 2.5 & 17.7 & 1.463 & 21.2 & 0.1463 & 83.49 \\
Solis (CH) & 1986/2012 & B & 968 & 170 & 1.0 & 68.0 & 4.630 & 103.0 & 0.4630 & 66.02 \\
Val d'Ambra (CH) & 1967/1967 & A & 512 & 85 & 2.5 & 8.0 & 0.436 & 8.7 & 0.0436 & 91.95 \\
\bottomrule
{$= V_s,out/V_s,in$} \\
\end{tabular}
\label{tab:addlabel}
\end{table}
\end{landscape}
\end{document}
由于某种原因,我在标题中看到了这些奇怪的星号,而且标题也未对齐。表格可能没有因边距(红色)而缩小,因为它仍然距离表格边距相当远。
我将非常感谢您的帮助和建议。
答案1
根据 leandris 的非常好的回答,我测试了该包nicematrix
。它提供了一个命令\Block
,允许在单元格内部使用\\
,还可以创建列/行块。因此,代码得到了简化,尽管如果格式发生变化,则需要进行第二次编译。
结果是一样的。我只是在单元格之间添加了一些垂直空间,并提高了视野 \cmidrule{10-11}
。
在任一答案中,也可以使用\renewcommand{\arraystretch}{1.7}
后获得细胞的拉伸 。\centering
\documentclass[a4paper, oneside]{article}
\usepackage{caption}
\usepackage{tabulary}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{ragged2e}
\usepackage{geometry}
\usepackage{siunitx}
\sisetup{per-mode=symbol}
\DeclareSIUnit \annum{a}
\usepackage{pdflscape}
\usepackage{nicematrix} % added
\begin{document}
\begin{landscape}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{NiceTabular}[%
cell-space-top-limit = 5pt, % stretch the cells
cell-space-bottom-limit = 5pt
]
{c
c
c
S[table-format=4]
S[table-format=3]
S[table-format=3.1]
S[table-format=3.1]
S[table-format=1.3]
S[table-format=3.1]
S[table-format=1.4]
S[table-format=2.2]
}
\toprule
\Block[c]{}{Reservoir\\ (Location)}
& \Block[c]{}{Dam/SBT \\ Commissioning \\ year}
& \Block[c]{}{SBT \\ Type \\ (A/B)}
& \Block[c]{}{SBT \\ length \\ {[\si{\metre}]}}
& \Block[c]{}{$Q_d$ \\ {[\si{\cubic\metre\per\second}]}}
& \Block[c]{}{$t_{op}$ \\ {[\si{\day\per\annum}]}}
& \Block[c]{}{$V_{s,m,\mathrm{out}}$ \\ {[\SI{E3}{\cubic\metre\per\annum}]}}
& \Block[c]{}{$\sigma_{s,m}$ \\ {[\si{\mL\per\L}]}}
& \Block[c]{}{MAS \\ {[\SI{E3}{\cubic\m\per\annum}]}}
& \Block{1-2}{Bypassing\\ efficiencies $\eta_{b}$ } \\[-7pt] % raise the next rule
\cmidrule{10-11}
& & & & & & & & & {$\eta_{\sigma}$} {[\si{\percent}]} & {$\eta_v$} {[\si{\percent}]}\\
\midrule
Asahi (JP) & 1987/1998 & A & 2384 & 140 & 14.5 & 65.0 & 0.371 & 109.4 & 0.0371 & 59.43 \\
Miwa (JP) & 1952/2004 & B & 4308 & 300 & 2.5 & 400.0 & 6.173 & 685.0 & 0.6173 & 58.39 \\
Palagnedra (CH) & 1952/1974 & A & 1760 & 250 & 5.0 & 92.0 & 0.852 & 200.0 & 0.0852 & 46.00 \\
Pfaffensprung (CH) & 1921/1922 & ns & 280 & 220 & 150.0 & 94.0 & 0.033 & 100.0 & 0.0033 & 94.00 \\
Rempen (CH) & 1924/1983 & A & 450 & 80 & 3.0 & 4.0 & 0.193 & ns & 0.0193 & ns \\
Runcahez (CH) & 1961/1961 & A & 572 & 56 & 2.5 & 17.7 & 1.463 & 21.2 & 0.1463 & 83.49 \\
Solis (CH) & 1986/2012 & B & 968 & 170 & 1.0 & 68.0 & 4.630 & 103.0 & 0.4630 & 66.02 \\
Val d'Ambra (CH) & 1967/1967 & A & 512 & 85 & 2.5 & 8.0 & 0.436 & 8.7 & 0.0436 & 91.95 \\
\bottomrule
{$= V_s,out/V_s,in$} \\
\end{NiceTabular}
\label{tab:addlabel}
\end{table}
\end{landscape}
\end{document}
答案2
您问题中的示例代码在尝试编译时会产生一堆错误消息。由于您提供了屏幕截图并提到了“标题中的奇怪星号”和错位:请永远不要忽略错误消息!即使您得到的东西乍一看像 pdf 文件,它仍然可能存在问题。出现错误后,TeX 只会尝试恢复足够的内容以对文件进行语法检查,而不会尝试在出现错误后做出合理的输出。
\makecell
此示例代码中的错误消息是由于在类型列中使用 而导致的S
。要纠正此问题,请用一\makecell
组额外的 包围每个命令{}
。事实上,所有不是数字但位于S
类型列内的内容都应被一组 包围,{}
以将其“隐藏”在解析机制中。包含在一组 `{} 中的内容将在其列内水平居中。
\documentclass[a4paper, oneside]{article}
\usepackage{caption}
\usepackage{tabulary}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{ragged2e}
\usepackage{geometry}
\usepackage{siunitx}
\sisetup{per-mode=symbol}
\DeclareSIUnit \annum{a}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{c
c
c
S[table-format=4]
S[table-format=3]
S[table-format=3.1]
S[table-format=3.1]
S[table-format=1.3]
S[table-format=3.1]
S[table-format=1.4]
S[table-format=2.2]
}
\toprule
\makecell{Reservoir\\ (Location)}
& \makecell{Dam/SBT \\ Commissioning \\ year}
& \makecell{SBT \\ Type \\ (A/B)}
& {\makecell{SBT \\ length \\ {[\si{\metre}]}}}
& {\makecell{$Q_d$ \\ {[\si{\cubic\metre\per\second}]}}}
& {\makecell{$t_{op}$ \\ {[\si{\day\per\annum}]}}}
& {\makecell{$V_{s,m,\mathrm{out}}$ \\ {[\SI{E3}{\cubic\metre\per\annum}]}}}
& {\makecell{$\sigma_{s,m}$ \\ {[\si{\mL\per\L}]}}}
& {\makecell{MAS \\ {[\SI{E3}{\cubic\m\per\annum}]}}}
& \multicolumn{2}{c}{\makecell{Bypassing\\ efficiencies $\eta_{b}$ }} \\
\cmidrule{10-11}
& & & & & & & & & {$\eta_{\sigma}$ [\si{\percent}]} & {$\eta_v$ [\si{\percent}]}\\
\midrule
Asahi (JP) & 1987/1998 & A & 2384 & 140 & 14.5 & 65.0 & 0.371 & 109.4 & 0.0371 & 59.43 \\
Miwa (JP) & 1952/2004 & B & 4308 & 300 & 2.5 & 400.0 & 6.173 & 685.0 & 0.6173 & 58.39 \\
Palagnedra (CH) & 1952/1974 & A & 1760 & 250 & 5.0 & 92.0 & 0.852 & 200.0 & 0.0852 & 46.00 \\
Pfaffensprung (CH) & 1921/1922 & ns & 280 & 220 & 150.0 & 94.0 & 0.033 & 100.0 & 0.0033 & 94.00 \\
Rempen (CH) & 1924/1983 & A & 450 & 80 & 3.0 & 4.0 & 0.193 & {ns} & 0.0193 & {ns} \\
Runcahez (CH) & 1961/1961 & A & 572 & 56 & 2.5 & 17.7 & 1.463 & 21.2 & 0.1463 & 83.49 \\
Solis (CH) & 1986/2012 & B & 968 & 170 & 1.0 & 68.0 & 4.630 & 103.0 & 0.4630 & 66.02 \\
Val d'Ambra (CH) & 1967/1967 & A & 512 & 85 & 2.5 & 8.0 & 0.436 & 8.7 & 0.0436 & 91.95 \\
\bottomrule
{$= V_s,out/V_s,in$} \\
\end{tabular}
\label{tab:addlabel}
\end{table}
\end{landscape}
\end{document}