tabularx 中有多行?

tabularx 中有多行?

我们可以在 tabularx 中使用多行吗?它似乎不起作用并且识别:

\multirow{2}{*}{95\% Confidence

完整代码:

\documentclass{article}
\usepackage{makecell} % for bold in table using \small
\renewcommand\theadfont{\small} % for bold in table using \small
\usepackage{tabularx, ragged2e} 
\usepackage{booktabs}

\begin{document}

\begin{table}[!ht]
\centering
    \begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xccc}
    \toprule
    & &  & \thead{\small {\textbf{Statistic}}}& \thead{\small {\textbf{Std. Error}}} \\
\midrule
    \multicolumn{1}{l}{Difference} & Mean
    & & 44.20000 & 4.54068  \\
\cline{2-5}
    & \multirow{2}{*}{95\% Confidence Interval for Mean} & Lower Bound & 33.9283 & \\
\cline{3-5}
    & & Upper Bound & \54.4717 \\
\cline{2-5}
    & Kurtosis & & -1.000 & 1.334 \\
\bottomrule
    \end{tabularx}
\end{table}

\end{document}

结果:

在此处输入图片描述

我实际上想要类似下面的东西:

在此处输入图片描述

答案1

您可以 1) 加载multirow并 2) 使用=键,因为您处于固定宽度列中。我擅自使用S最后两列的列类型,将数字对齐到小数点,并设置列标题的字体,而不是在表格中对每个标题进行硬编码。此外,我将 s 替换\cline\cmidrules 以在规则周围添加一些填充。

\documentclass{article}
\usepackage{makecell} % for bold in table using \small
\renewcommand\theadfont{\small} % for bold in table using \small
\usepackage{tabularx, ragged2e, multirow}
\usepackage{booktabs}
\usepackage{siunitx}
\renewcommand{\theadfont}{\small\bfseries}

\begin{document}

\begin{table}[!ht]
\centering
\sisetup{table-number-alignment=center}
    \begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}XcS[table-format=-1.5]S[table-format=1.5]}
    \toprule
    & & & {\thead{Statistic}}& {\thead{Std. Error}} \\
\midrule
    \multicolumn{1}{l}{Difference} & Mean
    & & 44.20000 & 4.54068 \\
\cmidrule{2-5}
    & \multirow{2}{=}{95\% Confidence Interval for Mean} & Lower Bound & 33.9283 & \\
\cmidrule{3-5}
    & & Upper Bound & \ 54.4717 \\
\cmidrule{2-5}
    & Kurtosis & & -1.000 & 1.334 \\
\bottomrule
    \end{tabularx}
\end{table}

\end{document} 

在此处输入图片描述

答案2

我不会使用\multirow指令。相反,我会将单元格内容放入定制tabular环境中,如下例所示。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx, % for 'tabularx' env.
            ragged2e, % for \RaggedRight macro
            booktabs, % for \toprule, \midrule, etc
            siunitx,  % for 'S' column type
            amsmath}  % for [b] option of \smash command
\sisetup{group-digits=false}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\newcommand\mytab[1]{\smash[b]{%
    \begin{tabular}[t]{@{}L@{}} #1 \end{tabular}}}

\begin{document}

\begin{table}[!ht]
%%\centering % not needed
\begin{tabularx}{\textwidth}{ @{} l L l 
    S[table-format=-1.5] 
    S[table-format= 1.5] @{}}
\toprule
& & & {Statistic} & {Std.\ Error} \\
\midrule
Difference & Mean & & 44.20000 & 4.54068  \\
\cmidrule(l){2-5}
& \mytab{95\% Confidence Interval for Mean} & Lower Bound & 33.9283 & \\
\cmidrule(l){3-5}
& & Upper Bound & 54.4717 \\
\cmidrule(l){2-5}
& Kurtosis & & -1.000 & 1.334 \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

答案3

如果你calstable使用包排版卡路里,水平跨越单元格并垂直居中,很容易。

在此处输入图片描述

\documentclass[british, DIV=12, captions=tableheading]{scrartcl}
\usepackage{cals, url}
\usepackage{babel}
\usepackage{xcolor}
\usepackage[footnotefigures]{MinionPro}
\input{glyphtounicode}
\pdfgentounicode=1
\usepackage[scaled=0.86]{luximono}
\RequirePackage[utf8]{inputenx}
\RequirePackage[T1]{fontenc}

\RequirePackage[letterspace=100,%
                babel=true,%
                tracking=true,%
                kerning=true]%
        {microtype}

\renewcommand{\sfdefault}{uop}
\let\nc=\nullcell                                                  % Shortcuts
\let\sc=\spancontent

\addtokomafont{caption}{\sffamily\bfseries\small}
\setkomafont{captionlabel}{\normalfont}

\begin{document}

\begin{table*}
\caption{A caption}
\begin{calstable}[c]
% Defining columns relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth)/6\relax}
            {\dimexpr(\columnwidth)/5\relax}
            {\dimexpr(\columnwidth)/6\relax}
            {\dimexpr(\columnwidth)/6\relax}
            {\dimexpr(\columnwidth)/6\relax}
            }
% The tabular fills the text area if sum of all columns is 5

% Set up the tabular
\makeatletter
\def\cals@framers@width{0.8pt}   % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0pt}
\def\cals@bodyrs@width{0.6pt}
\cals@setpadding{Ag}
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0pt}             % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.6pt}
\def\cals@bgcolor{}

\def\bb{\ifx\cals@borderB\relax     % Botton border switch (off-on)
    \def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}

\def\lp{\ifdim\cals@paddingL=0.0pt\relax    % Left padding switch (off-on)
    \cals@setpadding{Ag}
\else \setlength{\cals@paddingL}{0pt}\fi}

\def\rp{\ifdim\cals@paddingR=0.0pt\relax    % Right padding switch (off-on)
    \cals@setpadding{Ag}
\else \setlength{\cals@paddingR}{0pt}\fi}

% R1H1
\thead{\bfseries%
\brow
    \lp\cell{}\lp
    \cell{}
    \cell{}
    \alignR\cell{\vfil Statistics}
    \rp\alignR\cell{\vfil Std. Error}\rp
\erow
\mdseries%
}
\tfoot{\lastrule\strut}
%R2B1
\brow
    \lp\bb\alignL\cell{Difference}\lp
    \bb\alignL\cell{Mean}
    \cell{}
     \alignR\cell{44.200\,00}
    \rp\alignR\cell{4.540\,68}\rp\bb
\erow
%R3B2
\brow
    \lp\cell{}\lp
    \nc{lrt}
    \bb\alignL\cell{Lower Bound}
    \alignR\cell{33.928\,30}
    \rp\cell{}\rp\bb
\erow
%R4B3
\brow
    \lp\cell{}\lp
    \bb\nc{lrb}\alignL\sc{\vfil 95\% Confidence\\ Interval for Mean}
    \alignL\cell{Upper Bound}
    \alignR\cell{54.471\,70}
    \rp\cell{}\rp
\erow
%R5B4
\brow
    \lp\cell{}\lp
    \alignL\cell{Kurtosis}
    \cell{}
    \alignR\cell{-1.000\hspace*{0.9em}}
    \rp\alignR\cell{1.334\hspace*{0.9em}}\rp
\erow
\makeatletter
\end{calstable}\par
\end{table*}

\end{document}

相关内容