我将非常感谢在多行环境中将文本居中的建议。在下面的表格中,多行文本“blah blah blah blah blah blah blah blah”并未在其跨越的九行上居中。
\begin{table}[]
\centering
\caption{}
\label{tab:my-table}
\resizebox{\textwidth}{!}{%
\begin{tabular}{@{}ccccccll@{}}
\toprule
\textbf{Ref.} &
\textbf{Time} &
\textbf{\begin{tabular}[c]{@{}c@{}}Specs\\ Selection\end{tabular}} &
\textbf{\begin{tabular}[c]{@{}c@{}}Specs\\ Selection\end{tabular}} &
\textbf{\begin{tabular}[c]{@{}c@{}}Specs\\ Selection\end{tabular}} &
\textbf{\begin{tabular}[c]{@{}c@{}}Specs\\ Selection\end{tabular}} &
\multicolumn{1}{c}{\textbf{\begin{tabular}[c]{@{}c@{}}Specs\\ Selection\end{tabular}}} &
\multicolumn{1}{c}{\textbf{\begin{tabular}[c]{@{}c@{}}Specs\\ Selection\end{tabular}}} \\ \midrule
1 &
20159 &
\ding{55} &
\ding{55} &
\ding{51} &
\ding{51} &
- Demand side management &
\multirow{9}{*}{\begin{tabular}[c]{@{}l@{}}blah blah blah blah blah blah blah blah\\ bbbbb bbb bbbbb bbbb bbbbbb bbbbb \\ bbbb bbbbbbbbbbb bbbbbbbbbbbbb bb\\ bbb bbb bbbbb bbbb bbbb bbbb bbb bb\\ bbb bbbbb bbbb bbbb bbbbb bbbb bbb \\ bbb bbb bbb bbb bbb bbb bbb bb bbb\end{tabular}} \\ \cmidrule(r){1-7}
2 & 2018 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & - Demand side management & \\ \cmidrule(r){1-7}
3 & 2014 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & - Demand side management & \\ \cmidrule(r){1-7}
4 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & - Demand side management & \\ \cmidrule(r){1-7}
5 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & - Demand side management & \\ \cmidrule(r){1-7}
6 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & - Demand side management & \\ \cmidrule(r){1-7}
7 & 2016 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & - Demand side management & \\ \cmidrule(r){1-7}
[22] & 2015 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & - Demand side management & \\ \cmidrule(r){1-7}
Our & 2021 & \ding{51} & \ding{51} & \ding{51} & \ding{51} & - Demand side management & \\ \bottomrule
\end{tabular}%
}
\end{table}
答案1
(红线表示文字边框)
对于多行单元格内容的垂直居中,您需要估计其高度上应该有多少行文本:
相邻列 9 行 + 表格水平线周围 10 行 ~ 12 行
\documentclass{article}
\usepackage[margin=20mm]{geometry}
\usepackage{pifont}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\usepackage[skip=1ex]{caption}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\begin{table}[ht]
\caption{}
\label{tab:my-table}
\footnotesize
\setlength\tabcolsep{4pt}
\centering
\begin{tabularx}{\linewidth}{@{} cc cc cc l X @{}}
\toprule
\thead{Ref.}
& \thead{Time}
& \thead{Specs\\ Sel.}
& \thead{Specs\\ Sel.}
& \thead{Specs\\ Sel.}
& \thead{Specs\\ Sel.}
& \thead{Specs\\ Sel.}
& \thead{Specs\\ Sel.} \\
\midrule
1 & 20159 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \multirow{12}[5]{=}{%
blah blah blah blah blah blah blah blah
bbbbb bbb bbbbb bbbb bbbbbb bbbbb bbbbb
bbbbb bbbbbb bbbbbb bbbb bbb bb bbb bbb
bbbb bbbb bbbb bbb bb bbb bbbbb bbbb bb
bbbb bbbbb bbbb bbb bbb bbb bbb bbb bbb
bbb bbb bb bbb} \\
\cmidrule(r){1-7}
2 & 2018 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \\
\cmidrule(r){1-7}
3 & 2014 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \\
\cmidrule(r){1-7}
4 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \\
\cmidrule(r){1-7}
5 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \\
\cmidrule(r){1-7}
6 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \\
\cmidrule(r){1-7}
7 & 2016 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \\
\cmidrule(r){1-7}
[22]& 2015 & \ding{55} & \ding{55} & \ding{51} & \ding{51}
& - Demand side management & \\
\cmidrule(r){1-7}
Our & 2021 & \ding{51} & \ding{51} & \ding{51} & \ding{51}
& - Demand side management & \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
笔记: 我擅自在上述 MWE 中提出以下建议:
- 对于列标题,请使用包
thead
中定义的指令makcell
, tabular
删除多行单元格中的使用,并将其定义为\multirow{12}[5]{=}{...}
其中[5]
是多行单元格中的文本行数- 由于表格比较宽,最好
tabular
使用tabularx
宽度规定为与文本宽度相等的表格(通过\linewidth
}
答案2
\documentclass[10pt,a4paper]{article}
\usepackage{ pifont, lipsum}
\usepackage{booktabs,multirow,array,caption}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}[]
\centering
\caption{}
\label{tab:my-table}
% {\textwidth}{!}{%
\begin{tabular}{@{}cccccccP{5cm}@{}}
\toprule
\textbf{Ref.} &
\textbf{Time} &
\multicolumn{6}{c}{\textbf {Spec Selection}} \\ \midrule
1 &
20159 &
\ding{55} &
\ding{55} &
\ding{51} &
\ding{51} &
@ &
\multirow{9}{=}{\centering \lipsum[75]} \\ \cmidrule(r){1-7}
2 & 2018 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & @ & \\ \cmidrule(r){1-7}
3 & 2014 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & @ & \\ \cmidrule(r){1-7}
4 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & @ & \\ \cmidrule(r){1-7}
5 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & @ & \\ \cmidrule(r){1-7}
6 & 2017 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & @ & \\ \cmidrule(r){1-7}
7 & 2016 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & @ & \\ \cmidrule(r){1-7}
[22] & 2015 & \ding{55} & \ding{55} & \ding{51} & \ding{51} & @ & \\ \cmidrule(r){1-7}
Our & 2021 & \ding{51} & \ding{51} & \ding{51} & \ding{51} & @ & \\\midrule[1.5pt]
\multicolumn{8}{l}{@=some text to define column 7}\\ \bottomrule
\end{tabular}%
% }
\end{table}
\end{document}