`表格` 环境中文本或数字的中央对齐

`表格` 环境中文本或数字的中央对齐

multicolumn我想知道如何在环境中使用时将文本或数字居中对齐Table。我需要准备一个表格,如下图所示。我的论文表格

上表内容MWE如下:

\documentclass{article}

%%%%%%%%%% PACKAGES %%%%%%%%%%%%%%%%%%%%%%
\usepackage{multirow}
\usepackage{calc}
\usepackage{array}
\newcolumntype{L}[1]{> 
{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{> 
{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
    \newcolumntype{R}[1]{> 
{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcommand{\mc}[3]{\multicolumn{#1}{#2}{#3}}
\newcommand{\mr}[3]{\multirow{#1}{#2}{#3}}
\usepackage{booktabs}
\begin{document}

\begin{table}[ht!]
 \begin{center}
\begin{tabular}{cccccccccccccc}\hline 
 \mc{2}{|C{0.75cm}|}{} & \mc{3}{C{2cm}|}{} & \mc{3}{C{3cm}|}{1} & \mc{3}{C{3cm}|}{2} & \mc{3}{C{3cm}|}{3}\\ \hline 
%-----------------------------------------------------------------------------------------------------------------------
 \mc{2}{|C{0.75cm}|}{} & \mc{3}{C{2cm}|}{} & \mc{3}{p{3cm}|}{\centering $T_{\alpha}^{-1}$ exists and \\ is bounded } & \mc{3}{p{3cm}|}{\centering $T_{\alpha}^{-1}$ exists and \\ is unbounded } & \mc{3}{C{3cm}|}{$T_{\alpha}^{-1}$ does not exists}\\ \hline
%-----------------------------------------------------------------------------------------------------------------------
\mc{2}{|L{0.75cm}|}{$I$} & \mc{3}{C{2.5cm}|}{$R(T-\alpha I)=X$} & \mc{3}{p{3cm}|}{$\alpha \in \rho (T,X)$} & \mc{3}{C{3cm}|}{$-$} & \mc{3}{p{3cm}|}{\centering$\alpha \in \sigma_{p} (T,X)$ \\ $\alpha \in \sigma_{ap} (T,X)$}\\ \hline
\end{tabular}
 \end{center}
\end{table}
%
 \end{document}

输出结果MWE与图片类似。唯一的问题是文本或数字的对齐。

请帮忙或者提供建议吗?

答案1

避免被监禁的表:

\documentclass{article}

%%%%%%%%%% PACKAGES %%%%%%%%%%%%%%%%%%%%%%
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}

\newcolumntype{C}{>{\centering}X}

\begin{document}

\begin{table}[ht!]
\centering
\renewcommand{\tabularxcolumn}{m}

\begin{tabularx}{\textwidth}{@{}ccCCC@{}}
\toprule
&& 1 & 2 & 3 \tabularnewline
\cmidrule(lr){3-3} \cmidrule(lr){4-4} \cmidrule(l){5-5}
&& $T_{\alpha}^{-1}$ exists and \\ is bounded &
   $T_{\alpha}^{-1}$ exists and \\ is unbounded & 
   $T_{\alpha}^{-1}$ does not exist \tabularnewline
\midrule
$I$ & $R(T-\alpha I)=X$ & $\alpha \in \rho (T,X)$ & --- & 
$\alpha \in \sigma_{p} (T,X)$ \\ $\alpha \in \sigma_{ap} (T,X)$ \tabularnewline
\bottomrule
\end{tabularx}

\end{table}

\end{document}

仅定义您需要的列。这里两个列以其自然宽度居中,然后三个列相等。对于所有列,垂直和水平居中。

由于您想指定换行符,因此我没有说明\arraybackslash并用于\tabularnewline结束行。

在此处输入图片描述

不过,将其关进监狱很容易。

\begin{tabularx}{\textwidth}{|c|c|C|C|C|}
\hline
&& 1 & 2 & 3 \tabularnewline
\hline
&& $T_{\alpha}^{-1}$ exists and \\ is bounded &
   $T_{\alpha}^{-1}$ exists and \\ is unbounded &
   $T_{\alpha}^{-1}$ does not exist \tabularnewline
\hline
$I$ & $R(T-\alpha I)=X$ & $\alpha \in \rho (T,X)$ & --- &
$\alpha \in \sigma_{p} (T,X)$ \\ $\alpha \in \sigma_{ap} (T,X)$ \tabularnewline
\hline
\end{tabularx}

在此处输入图片描述

答案2

我想你已经快到了。

\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{bbm}
\begin{document}

\newcolumntype{C}{>{\centering\arraybackslash}p{3cm}}

\begin{table}
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{|l|l|C|C|C|}
\hline
             &                   & 1              &2                 & \multicolumn{1}{c|}{3}                                                                                  \\ \hline
             &                   & $T_\alpha^{-1}$ exists and is bounded & $T_\alpha^{-1}$ exists and is unbounded & $T_\alpha^{-1}$ does not exist                                                                         \\ \hline
$\mathbbm{1}$ & $R(T-\alpha \mathbbm{1})=X$ & $\alpha \in \rho (T,X)$               & -                                       & 
$\begin{array}{r@{}l}
\alpha& \in \sigma_{p} (T,X)\\ \alpha& \in \sigma_{ap} (T,X)
\end{array}$ \\ \hline
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案3

使用tabularx可让您更灵活地进行换行和总页面宽度表。要将单元格居中,请使用\multicolumn{1}{c|}{..},您可以通过增加行的垂直空间\renewcommand{\arraystretch}{1.3}来提高可读性。最后一行的单元格可以使用 垂直居中\multirow,但这不会有太大区别。

\documentclass{article}
\usepackage{array,tabularx}
\begin{document}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\begin{table}
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\textwidth}{|l|l|L|L|L|}
\hline
             &                   & \multicolumn{1}{c|}{1}                & \multicolumn{1}{c|}{2}                  & \multicolumn{1}{c|}{3}                                                                                  \\ \hline
             &                   & $T_\alpha^{-1}$ exists and is bounded & $T_\alpha^{-1}$ exists and is unbounded & $T_\alpha^{-1}$ does not exists                                                                         \\ \hline
        $I$  & $R(T-\alpha I)=X$ & $\alpha \in \rho (T,X)$               & -                                       & $\alpha \in \sigma_{p} (T,X)$ \newline $\alpha \in \sigma_{ap} (T,X)$ \\ \hline
\end{tabularx}
\end{table}

\end{document}

在此处输入图片描述

您可能还想使用booktabs以下方法改进整个设计:

\documentclass{article}
\usepackage{array,tabularx,booktabs}
\begin{document}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\begin{table}
%\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\textwidth}{@{}llLLL@{}}
\toprule
             &                   & \multicolumn{1}{c}{1}                & \multicolumn{1}{c}{2}                  & \multicolumn{1}{c}{3}                                                                                  \\ \midrule
             &                   & $T_\alpha^{-1}$ exists and is bounded & $T_\alpha^{-1}$ exists and is unbounded & $T_\alpha^{-1}$ does not exists                                                                         \\ 
\textit{$I$} & $R(T-\alpha I)=X$ & $\alpha \in \rho (T,X)$               & -                                       & $\alpha \in \sigma_{p} (T,X)$ \newline $\alpha \in \sigma_{ap} (T,X)$ \\ \bottomrule
\end{tabularx}
\end{table}

\end{document}

在此处输入图片描述

相关内容