我想要一个看起来像这样的表格,但没有 MULTI 上方和下方的水平线:
我的代码如下:
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{multirow}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{table}
\centering
\caption{Table}
\label{tab:table}
\begin{tabular}{M{0.1\textwidth} M{0.2\textwidth} M{0.2\textwidth} M{0.23\textwidth} M{0.12\textwidth}}
TEXT & TEXT & TEXT & TEXT & TEXT \\ \specialrule{.2em}{.1em}{.1em}
TEXT & \multirow{3}{*}[-2pt]{MULTI} & TEXT & TEXT & TEXT \\ \hline
TEXT & & TEXT & TEXT & TEXT \\ \hline
TEXT & & TEXT & TEXT & TEXT \\ \specialrule{.1em}{.05em}{.05em}
\end{tabular}
\end{table}
\end{document}
我检查了这但我无法让它工作。
答案1
只需删除\hline
MWE 中的即可。希望它有效!
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{multirow}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{table}
\centering
\caption{Table}
\label{tab:table}
\begin{tabular}{M{0.1\textwidth} M{0.2\textwidth} M{0.2\textwidth} M{0.23\textwidth} M{0.12\textwidth}}
TEXT & TEXT & TEXT & TEXT & TEXT \\ \specialrule{.2em}{.1em}{.1em}
TEXT & \multirow{3}{*}[-2pt]{MULTI} & TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\ \specialrule{.1em}{.05em}{.05em}
\end{tabular}
\end{table}
\end{document}
答案2
正如@Sebastián V. Romero 在他的回答中提到的,如果你不喜欢水平线(在你的情况下它们是由命令绘制的\hline
),请从表格主体代码中删除这些命令。
除此之外,您的 MWE 还有两个问题:
- 表格比文本区域宽(见第一个表格)
- 该
\multirow
单元格的宽度不会超过列的规定宽度,使用 intesd*
选项=
,可以超越列宽设置。
\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{array, booktabs, multirow}
\usepackage{caption}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{table}[ht]
\centering
\caption{Table (1)}
\label{tab:table}
\begin{tabular}{*{5}{M{0.2\textwidth}}}
\toprule %?
TEXT & TEXT & TEXT & TEXT & TEXT \\
\midrule
TEXT & \multirow{3}{=}{MULTI} & TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[ht]
\centering
\caption{Table (2)}
\label{tab:table}
\begin{tabular}{ *{5}{M{\dimexpr0.2\textwidth-2\tabcolsep}} }
\toprule %?
TEXT & TEXT & TEXT & TEXT & TEXT \\
\midrule
TEXT & \multirow{3}{=}{MULTI} & TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
(红线表示页面布局)
补充(已编辑):在这种情况下,多行单元格(MULTI)的内容应该水平居中,您需要更改\multirowsetup
:
\renewcommand\multirowsetup{\centering}
即:第二个表的完整 MWE 为:
\documentclass{article}
\usepackage{array, booktabs, multirow}
\usepackage{caption}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{table}[ht]
\centering
\caption{Table (2)}
\label{tab:table}
\renewcommand\multirowsetup{\centering} % <---
\begin{tabular}{ *{5}{M{\dimexpr0.2\textwidth-2\tabcolsep}} }
\toprule %?
TEXT & TEXT & TEXT & TEXT & TEXT \\
\midrule
TEXT & \multirow{3}{=}{MULTI}
& TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\
TEXT & & TEXT & TEXT & TEXT \\
\bottomrule
\end{tabular}
\end{table}
\end{document}