4

I want to know how to centre-align a text or a number while using multicolumn in Table environment. I need to prepare a table as shown in the image below. Table for my paper

The MWE for the above table is as follows:

\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}

The output of the MWE looks similar to the one in the image. The only issue is the alignment of the text or numbers.

Please help or provide suggestions?

3
  • What you want is not entirely clear. Must text or numbers be horizontally or vertically be centred (or both) in its cell?
    – Bernard
    Nov 23 '18 at 21:41
  • @Bernard The text or numbers should be centred vertically. I think they are horizontally centred in the cell.
    – Tanvir
    Nov 23 '18 at 23:39
  • The solutions provided below solved the problem I had with the alignment.
    – Tanvir
    Nov 24 '18 at 0:43
2

Avoid jailed tables:

\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}

Define only the columns you need. Here two centered columns at their natural width, then three equalized columns. For all columns, both vertical and horizontal centering.

Since you want to specify the line breaks, I don't state \arraybackslash and use \tabularnewline for ending rows.

enter image description here

It's easy to make it jailed, though.

\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}

enter image description here

3

I think you were almost there.

\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}

enter image description here

2

Using tabularx gives you more flexibility for line wrapping and total page width table. To center a cell use \multicolumn{1}{c|}{..} and you can increase vertical space for rows by \renewcommand{\arraystretch}{1.3} for more readability. Cells of the last row can be vertically centered by using \multirow but this will not make much difference.

\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}

enter image description here

You may also want to improve the whole design using booktabs as follows:

\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}

enter image description here

2
  • +1. Please replace \textit{$I$} with $I$, though.
    – Mico
    Nov 23 '18 at 22:20
  • The solution provided worked like charm. Also learnt a new thing -- using booktabs. This made the final table looked nice.
    – Tanvir
    Nov 24 '18 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.