我有以下代码:
\newcolumntype{Z}{>{\centering\arraybackslash}m{2.5cm}}
\newcolumntype{S}{>{\centering\arraybackslash}m{0.5cm}}
\begin{table*}[htbp]
\caption{Table Type Styles}
\begin{center}
\begin{tabular}{|S|S|c|S|Z|}
\hline
\multicolumn{2}{|c|}{\textbf{Model}} & \textbf{PL {[}dB{]}, $f_c$ {[}GHz{]}, $d$ {[}m{]}} & \textbf{$\sigma_{SF}$ {[}dB{]}} & \textbf{Applicability range and default values} \\ \hline
\multirow{2}{*}{\rotatebox{90}{3GPP UMa}} & \rotatebox{90}{LOS} & $\begin{aligned}[t]
PL_{\textnormal{UMa-LOS}} &=
\begin{cases}
PL_1 &\quad \text{if } 10\text{ m} \leq d_{2D} \leq d^{'}_{BP} \\
PL_2 &\quad \text{if } d^{'}_{BP} < d_{2D} \leq 5\text{ km} \end{cases} \\ PL_1 &= 28 + 22\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\ PL_2 &= 28 + 40\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\ &-9\log_{10}(({d^{'}_{\text{BP}}})^2 + h_{eff}^2)
\end{aligned} $ & 4 & \multirow{2}{*}{$\begin{aligned} 0.5<f_c<100 \text{ GHz} \\ 10 < d_{2D} < 5000\text{ m} \\ 1.5\leq h_{\text{UE}}\leq22.5\text{ m} \\ h_{\text{BS}}=25\text{ m} \end{aligned}$} \\ \cline{2-4}
& \rotatebox{90}{NLOS} & $\begin{aligned} PL_{\textnormal{UMa-NLOS}} &= \max\left(PL_{\textnormal{UMa-LOS}}, PL_{\textnormal{UMa-NLOS}}^{'}\right) \\ PL_{\textnormal{UMa-NLOS}}^{'} &= 13.54 + 39.08\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\& - 0.6\log_{10}(h_{\text{UE}}-1.5) \end{aligned}$& 6 & \\ \hline
\end{tabular}
\label{tab:models}
\end{center}
\end{table*}
编译后:
如何使所有单元格水平和垂直居中?
编辑1: @Zarko 解决方案几乎有效,但现在我需要在下面添加几行:
\multirow{2}{*}{\rotatebox{90}{mmMAGIC UMi}} & \rotatebox[origin=c]{90}{LOS} & $PL_{\textnormal{UMi-LOS}} = 32.9 + 19.2\log_{10}(d_{3D}) + 20.8\log_{10}(f_{c})$ & 2 & \multirow{2}{*}{} \\ \cline{2-4}
& \rotatebox[origin=c]{90}{NLOS} & $PL_{\textnormal{UMi-NLOS}} =31.0 + 45.0\log_{10}(d_{3D}) + 20.0\log_{10}(f_{c})$ & 7.82 & \\ \hline
当我这样做的时候: 有没有办法分成两个“垂直行”?此外,还发生了以下情况:
这与答案中的图不同。
答案1
您可以{NiceTabular}
使用nicematrix
。
- 您可以设置选项
cell-space-limits
(无需预先指定列)。 - 用于
\Block
合并单元格(水平和垂直)。 - 您使用密钥
hvlines
,并且所有规则均在块中绘制。
您可能需要编译两次。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\newcolumntype{Z}{>{\centering\arraybackslash}m{3cm}}
\newcolumntype{S}{>{\centering\arraybackslash}m{0.7cm}}
\begin{table*}[htbp]
\caption{Table Type Styles}
\begin{center}
\begin{NiceTabular}{Sw{c}{7mm}cSZ}[hvlines,cell-space-limits=3pt]
\Block{1-2}{\textbf{Model}}
&
& \textbf{PL {[}dB{]}, $f_c$ {[}GHz{]}, $d$ {[}m{]}}
& \textbf{$\sigma_{SF}$ {[}dB{]}}
& \textbf{Applicability range and default values}
\\
\Block{2-1}{\rotate 3GPP UMa}
& \rotatebox[origin=c]{90}{LOS}
& $\begin{aligned}
PL_{\textnormal{UMa-LOS}} & =
\begin{cases}
PL_1 & \quad \text{if } 10\text{ m} \leq d_{2D} \leq d^{'}_{BP} \\
PL_2 & \quad \text{if } d^{'}_{BP} < d_{2D} \leq 5\text{ km}
\end{cases} \\
PL_1 & = 28 + 22\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\
PL_2 & = 28 + 40\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\
& -9\log_{10}(({d^{'}_{\text{BP}}})^2 + h_{eff}^2)
\end{aligned} $
& 4
& \Block{2-1}%
{
$\begin{aligned}
0.5<f_c<100 \text{ GHz} \\
10 < d_{2D} < 5000\text{ m} \\
1.5\leq h_{\text{UE}}\leq22.5\text{ m} \\
h_{\text{BS}}=25\text{ m}
\end{aligned}$
}
\\
&\rotatebox[origin = c]{90}{NLOS}
& $\begin{aligned}
PL_{\textnormal{UMa-NLOS}} & = \max\left(PL_{\textnormal{UMa-LOS}}, PL_{\textnormal{UMa-NLOS}}^{'}\right) \\
PL_{\textnormal{UMa-NLOS}}^{'} & = 13.54 + 39.08\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\
& - 0.6\log_{10}(h_{\text{UE}}-1.5)
\end{aligned}$
& 6
& \\
\end{NiceTabular}
\end{center}
\end{table*}
\end{document}
答案2
\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{rotating}
\usepackage{cellspace, makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\addparagraphcolumntypes{C}
\begin{document}
\begin{table}[htbp]
\caption{Table Type Styles}
\label{tab:models}
\centering
\begin{tabularx}{\linewidth}{|*{4}{Sc|}>{\centering\arraybackslash}X|}
\hline
\multicolumn{2}{|c|}{\thead{Model}}
& \thead{PL {[}dB{]}, $f_c$ {[}GHz{]}, $d$ {[}m{]}}
& \thead{$\sigma_{SF}$\\ {[}dB{]}}
& \thead{Applicability range\\ and default values} \\ \hline
\multirow{8}{*}{\rotatebox{90}{3GPP UMa}}
& \rotatebox[origin=c]{90}{LOS}
& $\begin{aligned}
PL_{\mathrm{UMa-LOS}} & = \begin{cases}
PL_1 &\quad \text{if } 10\text{ m} \leq d_{2D} \leq d^{'}_{BP} \\
PL_2 &\quad \text{if } d^{'}_{BP} < d_{2D} \leq 5\text{ km}
\end{cases} \\
PL_1 & = 28 + 22\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\
PL_2 & = 28 + 40\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\
&\qquad
-9\log_{10}(({d^{'}_{\text{BP}}})^2 + h_{eff}^2)
\end{aligned}$
& 4
& \multirow{6}{=}{$\begin{aligned}
0.5< & f_c<100 \text{ GHz} \\
10 < & d_{2D} < 5000\text{ m} \\
1.5\leq & h_{\text{UE}}\leq22.5\text{ m} \\
& h_{\text{BS}}=25\text{ m}
\end{aligned}$} \\
\cline{2-4}
& \rotatebox[origin=c]{90}{NLOS}
& $\begin{aligned}
PL_{\mathrm{UMa-NLOS}}
& = \max\left(PL_{\mathrm{UMa-LOS}}, PL_{\mathrm{UMa-NLOS}}^{'}\right) \\
PL_{\mathrm{UMa-NLOS}}^{'}
& = 13.54 + 39.08\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\
&\qquad - 0.6\log_{10}(h_{\text{UE}}-1.5)
\end{aligned}$
& 6 & \\
\hline
\end{tabularx}
\end{table}
\end{document}
附录:
您应该知道,\multirow
单元格的高度必须等于或小于跨越相邻行的高度。如果不是这种情况,那么它们的内容将超出单元格,如您在编辑的问题中所示。为了防止这种情况,您有两种选择:
- 降低单元格高度
\multirow
(如在下一个 MWE 中所做的那样),或 - 增加跨行的高度,例如在这些行内容周围增加更大的垂直空间或在其中插入空行
考虑第一个选项时,您的表格可以写成如下形式:
\documentclass{article}
\usepackage{mathtools}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{} % new
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\RH[1]{\rotatebox[origin=c]{90}{\makecell{#1}}}% new
\usepackage{geometry}
\usepackage{siunitx} % new, used version 3
\begin{document}
\begin{table}[htbp]
\caption{Table Type Styles}
\label{tab:models}
\centering
\setcellgapes{7pt} % new
\makegapedcells % new
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{|*{4}{c|} C|}
\Xhline{1pt}
\multicolumn{2}{|c|}{\thead{Model}}
& \thead{PL {[\unit{dB}]}, $f_c$ {[\unit{GHz}]}, $d$ {[\unit{m}]}}
& \thead{$\sigma_{SF}^{}$\\ {[\unit{dB}]}}
& \thead{Applicability range\\ and default values} \\
\Xhline{0.8pt}
\multirow{8}{*}{\RH{3GPP UMa}}
& \RH{LOS}
& $\begin{aligned}
PL_{\mathrm{UMa-LOS}}
& = \begin{cases*}
PL_1 & if \qty{10}{m} $\leq d_{2D} \leq d^{'}_{BP}$ \\%[-1ex]
PL_2 & if $d^{'}_{BP} < d_{2D} \leq \qty{5}{km}$
\end{cases*} \\
PL_1 & = 28 + 22\log_{10}(d_{3D}) + 20\log_{10}(f_{c}) \\
PL_2 & = \begin{multlined}[t]
28 + 40\log_{10}(d_{3D}) + \\[-2ex]
20\log_{10}(f_{c}) -9 \log_{10}\bigl(({d'_{\text{BP}}})^2 + h_{eff}^2\bigr)
\end{multlined}
\end{aligned}$
& 4
& \multirow{8.4}{=}{$\begin{aligned}
0.5< & f_c<\qty{100}{GHz} \\
10 < & d_{2D} < \qty{5000}{m} \\
1.5\leq & h_{\text{UE}}\leq \qty{22.5}{m} \\
& h_{\text{BS}}=\qty{25}{m}
\end{aligned}$} \\
\cline{2-4}
& \RH{NLOS}
& $\begin{aligned}
PL_{\mathrm{UMa-NLOS}}
& = \max\left(PL_{\mathrm{UMa-LOS}}, PL_{\mathrm{UMa-NLOS}}^{'}\right) \\
PL_{\mathrm{UMa-NLOS}}^{'}
& = \begin{multlined}[t]
13.54 + 39.08\log_{10}(d_{3D}) + \\[-2ex]
20\log_{10}(f_{c}) - 0.6\log_{10}(h_{\text{UE}}-1.5)
\end{multlined}
\end{aligned}$
& 6 & \\
\hline
\multirow{2}{*}{\RH{mmMAGIC\\ UMi}}
& \RH{LOS}
& $PL_{\mathrm{UMi-LOS}}=32.9 + 19.2\log_{10}(d_{3D}) + 20.8\log_{10}(f_{c})$
& 2 & \\
\cline{2-4}
& \RH{NLOS}
& $PL_{\mathrm{UMi-NLOS}}=31.0 + 45.0\log_{10}(d_{3D}) + 20.0\log_{10}(f_{c})$
& 7.82 & \\
\Xhline{1pt}
\end{tabularx}
\end{table}
\end{document}
其生产成果为: