我正在尝试创建一个横跨页面垂直长度的横向表格。以下是我得到的结果:
该表几乎看起来不错,除了以下内容:
- 、
\toprule
和\midrule
没有\bottomrule
跨越表格的宽度。 - 使用
\cmidrule
而不是 之后\crule
,行之间的垂直间距增加,并且跨越多行的列标题看起来很糟糕。 - 继续第 2 点,有没有更好的方法让长列标题跨越多行?
最后,我可以在哪里找到该行的描述:\begin{tabularx}{\textwidth}{@{}*{14}{C}c@{}}
以下是生成该表的代码:
\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{tabularx,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of "X" type
\begin{document}
\begin{landscape}
\begin{table}
\caption{Summary of Columns}
\label{tab:OWCStandards}
\begin{tabularx}{\textwidth}{@{}*{14}{C}c@{}}
\toprule
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{First}}}
& \multicolumn{1}{c}{\multirow{3}{*}{\textbf{Second}}}
& \multicolumn{1}{c}{\multirow{3}{*}{\textbf{Third}}}
& \multicolumn{1}{c}{\multirow{2}{*}{\textbf{Fourth}}}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Fifth}}}
& \multicolumn{1}{c}{\multirow{3}{*}{\textbf{Sixth}}}
& \multicolumn{8}{c}{\multirow{1}{*}{\textbf{Multi-Column Here}}} \tabularnewline
\cmidrule[0.05em]{7-14}
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{Column}}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\multirow{2}{*}{\textbf{Column}}}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Columns}}}
& \multicolumn{1}{c}{}
& \multicolumn{6}{c}{\multirow{1}{*}{\textbf{Sub-column 1}}}
& \multicolumn{1}{c}{\multirow{2}{*}{\textbf{Sub-column 2}}}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Sub-column 3}}} \tabularnewline
\cmidrule{7-12}
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{Here}}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Here}}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\textbf{Col 1-1}}
& \multicolumn{1}{c}{\textbf{Col 1-2}}
& \multicolumn{1}{c}{\textbf{Col 1-3}}
& \multicolumn{1}{c}{\textbf{Col 1-4}}
& \multicolumn{1}{c}{\textbf{Col 1-5}}
& \multicolumn{1}{c}{\textbf{Col 1-6}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Here}}} \tabularnewline
\midrule
\midrule
%\midrule
\bottomrule
\end{tabularx}
\end{table}
\end{landscape}
\end{document}
编辑
我使用\linewidth
并添加了一行示例数据。这是我得到的结果:
\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{tabularx,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of "X" type
% \setlength{\extrarowheight}{1pt}
\begin{document}
\begin{landscape}
\begin{table}
\caption{Summary of Columns}
\label{tab:OWCStandards}
\begin{tabularx}{\linewidth}{@{}*{14}{C}c@{}}
\toprule
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{First}}}
& \multicolumn{1}{c}{\multirow{3}{*}{\textbf{Second}}}
& \multicolumn{1}{c}{\multirow{3}{*}{\textbf{Third}}}
& \multicolumn{1}{c}{\multirow{2}{*}{\textbf{Fourth}}}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Fifth}}}
& \multicolumn{1}{c}{\multirow{3}{*}{\textbf{Sixth}}}
& \multicolumn{8}{c}{\multirow{1}{*}{\textbf{Multi-Column Here}}} \tabularnewline
\cmidrule[0.05em]{7-14}
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{Column}}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\multirow{2}{*}{\textbf{Column}}}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Columns}}}
& \multicolumn{1}{c}{}
& \multicolumn{6}{c}{\multirow{1}{*}{\textbf{Sub-column 1}}}
& \multicolumn{1}{c}{\multirow{2}{*}{\textbf{Sub-column 2}}}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Sub-column 3}}} \tabularnewline
\cmidrule{7-12}
\multicolumn{1}{c}{\multirow{1}{*}{\textbf{Here}}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Here}}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\textbf{Col 1-1}}
& \multicolumn{1}{c}{\textbf{Col 1-2}}
& \multicolumn{1}{c}{\textbf{Col 1-3}}
& \multicolumn{1}{c}{\textbf{Col 1-4}}
& \multicolumn{1}{c}{\textbf{Col 1-5}}
& \multicolumn{1}{c}{\textbf{Col 1-6}}
& \multicolumn{1}{c}{}
& \multicolumn{1}{c}{\multirow{1}{*}{\textbf{Here}}} \tabularnewline
\midrule
\midrule
\multicolumn{1}{ c }{\multirow{2}{*}{Smart City}}
& \multicolumn{1}{c }{\multirow{2}{*}{2018}}
& \multicolumn{1}{c }{\multirow{2}{*}{\cite{}}}
& \multicolumn{1}{c }{\multirow{1}{*}{Smart}}
& \multicolumn{1}{c }{\multirow{2}{*}{Implementation}}
& \multicolumn{1}{c }{\multirow{2}{*}{Broadcast}}
& \multicolumn{1}{c }{\multirow{2}{*}{LED}}
& \multicolumn{1}{c }{\multirow{2}{*}{PD}}
& \multicolumn{1}{c }{\multirow{2}{*}{N/A}}
& \multicolumn{1}{c }{\multirow{2}{*}{1.5 m}}
& \multicolumn{1}{c }{\multirow{2}{*}{IEEE 802.11OCB}}
& \multicolumn{1}{c }{\multirow{2}{*}{N/A}}
& \multicolumn{1}{c }{\multirow{2}{*}{N/A}}
& \multicolumn{1}{c }{\multirow{2}{*}{N/A}} \tabularnewline
\multicolumn{1}{ c }{}& \multicolumn{1}{c }{}
& \multicolumn{1}{c }{} &\multicolumn{1}{c }{Vehicle}
&\multicolumn{1}{c }{} & \multicolumn{1}{c }{}
& \multicolumn{1}{c }{}& \multicolumn{1}{c }{}
& \multicolumn{1}{c }{} & \multicolumn{1}{c }{}
& \multicolumn{1}{c }{} & \multicolumn{1}{c }{}
& \multicolumn{1}{c }{} & \multicolumn{1}{c }{}
& \multicolumn{1}{c }{} \tabularnewline
\bottomrule
\end{tabularx}
\end{table}
\end{landscape}
\end{document}
答案1
tabularx
这就是为什么环境没有占据整个指定宽度的原因:即使你指定了 14 个居中版本的列类型X
,LaTeX 实际上也永远不会对它们采取行动,因为每一个细胞被包裹在\multicolumn{1}{c}{...}
“包装器”中;因此,LaTeX 所看到的只是c
列类型,而不是X
列类型。
无论如何,摆脱所有这些包装器是可能的,也是可取的——并且\multirow
也抛弃包装器。(该指令\renewcommand\tabularxcolumn[1]{m{#1}}
会自动安排单元格内容的垂直居中。)
\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pdflscape}
\usepackage{amsmath,tabularx,booktabs,ragged2e}
\newcolumntype{C}{>{\Centering\hspace{0pt}}X}
\renewcommand\tabularxcolumn[1]{m{#1}}
\newcommand\mytab[1]{% handy utility macro
\smash{\begin{tabular}[t]{@{}>{\Centering}p{\hsize}@{}}
\bfseries #1 \end{tabular}}}
\begin{document}
\begin{landscape}
\begin{table}
\setlength\tabcolsep{4pt} % default: 6pt
\caption{Summary of Columns}
\label{tab:OWCStandards}
\begin{tabularx}{\linewidth}{@{} *{14}{C} @{}}
\toprule
\mytab{First Column Here}
& \mytab{Second}
& \mytab{Third}
& \mytab{Fourth Column}
& \mytab{Fifth Column Here}
& \mytab{Sixth}
& \multicolumn{8}{c@{}}{\textbf{Multi-Column Here}}\\
\cmidrule(l){7-14}
& & & & &
& \multicolumn{6}{c}{\textbf{Sub-column 1}}
& \mytab{Sub-column 2}
& \mytab{Sub-column 3 Here}
\\
\cmidrule(lr){7-12}
& & & & &
& \textbf{Col 1-1} & \textbf{Col 1-2} & \textbf{Col 1-3}
& \textbf{Col 1-4} & \textbf{Col 1-5} & \textbf{Col 1-6}
\\
\midrule
Smart City
& 2018
& \cite{}
& Smart Vehicle
& Implementation
& Broadcast
& LED
& PD
& N/A
& 1.5 m
& IEEE 802.11OCB
& N/A
& N/A
& N/A
\\
\bottomrule
\end{tabularx}
\end{table}
\end{landscape}
\end{document}
答案2
具有环境的代码sidewaystable
,所有这些代码都\multicolumn{1}{c}
被删除了,并且系统地使用了\multirow{n}{=}{contents}
固定宽度的列,这使得可以 \\
在它们内部使用以在单元格中获取换行符:
\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{tabularx,booktabs}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of "X" type
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\usepackage{graphicx, rotating}
\usepackage{makecell}
\begin{document}
\begin{sidewaystable}
\setlength{\tabcolsep}{3pt}
\caption{Summary of Columns}
\label{tab:OWCStandards}
\begin{tabularx}{\textheight}{@{}*{14}{C}@{}}
\toprule
\multicolumn{6}{c}{}
& \multicolumn{8}{c}{\textbf{Multi-Column Here}} \tabularnewline
\cmidrule[0.05em]{7-14}
\multirow{-2}{=}{\bfseries\centering First\\ Column\\ Here}
& {\bfseries\centering Second }
&{\bfseries\centering Third}
& \multirow{-1.5}{=}{\bfseries \centering Fourth\\ Column}
& \multirow{-2}{=}{\bfseries\centering Fifth\\ Column \\ Here}
&{\bfseries\centering Sixth}
& \multicolumn{6}{c}{\textbf{Subcolumn 1}}
& \multirow{2}{=}{\small\bfseries\centering Subcolumn 2}
&\multirow{2}{=}{\small\bfseries\centering Subcolumn 3 Here} \tabularnewline%
\cmidrule{7-12}
\multicolumn{6}{c}{}
& \textbf{Col 1-1}
& \textbf{Col 1-2}
& \textbf{Col 1-3}
& \textbf{Col 1-4}
& \textbf{Col 1-5}
& \textbf{Col 1-6}
&
\tabularnewline
\midrule
\multicolumn{1}{ c }{Smart City}
& 2018
& \cite{}
& Smart Vehicle
& Implemen\-tation
& Broadcast
& LED & PD & N/A & 1.5 m
& IEEE 802.11OCB
& N/A & N/A & N/A
\tabularnewline
\midrule
\bottomrule
\end{tabularx}
\end{sidewaystable}
\end{document}