# How to build a table of fixed width and fixed height? (Edit: the question left now is about color overwrite)

\begin{frame}{Title}
\begin{equation*}
\begin{tabular}{cccc}

& aaaaaaaaaa & aaaaaaaaa & aaaaaaaaaaaaa \\ \cline{2-4}
$A_A \prec_B C_C$ & \multicolumn{1}{|c}{}
& \multicolumn{1}{|c}{}
&
\multicolumn{1}{|c|}{}
\\ \cline{2-4}
$A_A {\tiny\cancel{\overset{\prec}{\underset{\succ}{\approx}}}_B} C_C$ & \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c}{}
& \multicolumn{1}{|c|}{}

\\ \cline{2-4}
$A_A=C_C$ & \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c|}{}

\\ \cline{2-4}
$A_A \succ_B C_C$ & \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c|}{}
\\ \cline{2-4}

\end{tabular}
\end{equation*}
\end{frame}


(Deleted)The problem of width is caused by each column having different numbers of "a". And the problem of height is caused by a customized large symbol. I tried to replace the initial four "c" with "p{4cm}", but it does not respond at all. (this is for adjusting the width. As for height, shall I use something like "\renewcommand{\arraystretch}{1.5}"?) I have searched some threads, but their table starts with format like {|c|c|} and I feel that my case does not fit in?

There is also another problem: some lines are covered by the gray block. I tried to move \cline before \ rather than after \, but it always says "error". There are some relevant thread: Cellcolor overwrites partial horizontal lines (\cline) But their tables start with something like {|c|c|}, so all the border lines are present, which is inconsistent with my case.

Thank you very much!

Edit(delted):

\begin{frame}{Frame Title}
\noindent\begin{minipage}[t][6in][t]{\textwidth}
\centering
\begin{tabular}{@{} c p{1in} p{1in} p{1in} @{}}

& aaaaaaaaaa & aaaaaaaaa & aaaaaaaaaaaaa \\ \cline{2-4}
$A_A \prec_B C_C$ & \multicolumn{1}{|c}{}
& \multicolumn{1}{|c}{}
&
\multicolumn{1}{|c|}{}
\\ \cline{2-4}
$A_A \cancel{\overset{\prec}{\underset{\succ}{\approx}}}_B C_C$ & \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c}{}
& \multicolumn{1}{|c|}{}

\\ \cline{2-4}
$A_A=C_C$ & \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c|}{}

\\ \cline{2-4}
$A_A \succ_B C_C$ & \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c}{\cellcolor[HTML]{C0C0C0}}
& \multicolumn{1}{|c|}{}
\\ \cline{2-4}

\end{tabular}
\end{minipage}

\end{frame}

• @jsbibra Thank you very much! I tried the first one, it looks the width is OK, but the "aaaa" is not centered. As for the height, it does not respond at all. My new code is now in my question. Oct 9, 2021 at 2:16
• if just centering why not use c type columns Oct 9, 2021 at 2:54
• @jsbibra What I want is: the text is centered, but the width is fixed. Oct 9, 2021 at 2:56

Here is a solution with {NiceTabular} of nicematrix.

• The key columns-width=auto sets the width of all the columns to the largest one.

• I have set \arraystretch to 1.4, which, in your case, is enough to have all the rows of the same height.

• The command \Block[hvlines]{*-*}{} creates a block with no content (the last argument) but which is used to have all the rules drawn in that block (with the key hvlines).

• With {NiceTabular} of nicematrix, the rules are drawn by PGF (a sublayer of Tikz) after the construction of the array and that ensure a perfect result with the colored cells, in all the PDF viewers). However, you need several compilations.

\documentclass{beamer}
\usepackage{cancel}
\usepackage{nicematrix}

\begin{document}

\begin{frame}{Title}
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{cccc}[colortbl-like,columns-width=auto]
& aaaaaaaaaa & aaaaaaaaa & aaaaaaaaaaaaa \\
$A_A \prec_B C_C$ & \Block[hvlines]{*-*}{} \\
$A_A {\tiny\cancel{\overset{\prec}{\underset{\succ}{\approx}}}_B} C_C$ & \cellcolor{gray!50} \\
$A_A=C_C$ & \cellcolor{gray!50} & \cellcolor{gray!50} \\
$A_A \succ_B C_C$ & \cellcolor{gray!50} & \cellcolor{gray!50} \\
\end{NiceTabular}
\end{frame}

\end{document} • Thanks! I was wondering how to execute "several compilations". Oct 9, 2021 at 13:41
• As usual with LaTeX, compilations mus be done until the aux file does not change. Several tools, such as latexmk does directly the right number of compilations. Overleaf, for instance, uses latexmk (afaik) and the right number of compilations is always done. Oct 9, 2021 at 15:55
• Actually, I am using Overleaf. But when I copy and paste your code in, it shows several errors including "The option 'colortbl-like' is unknown for the missing number, treated as 0". Oct 9, 2021 at 16:01
• Overleaf has not the latest version of nicematrix. You should upload the latest version of the file nicematrix.sty in the repertory of your Overleaf project. You can find that file on the SVN server of TeXLive: www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty Oct 9, 2021 at 16:02
• Sorry my question may be stupid. But I went to the link you provided, but what I download is a txt file. And it does not work even if I uploaded it to Overleaf. I also created a tex file in which I pasted the code of txt in, but it also did not work. I guess I have a misunderstanding about sty file. Oct 9, 2021 at 16:23

I would wipe out all lines -- horizontal & vertical -- within the shaded area. \documentclass[table]{beamer}
\usepackage{cancel,xcolor,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering}X}
\newcommand\cc{\multicolumn{1}{c}{\cellcolor[HTML]{C0C0C0}}} % handy shortcut macro

\begin{document}
\begin{frame}{Title}
\begin{tabularx}{\textwidth}{l|*{3}{C|}}
\cline{2-4}
& aaaaaaaaaa & aaaaaaaaa & aaaaaaaaaaaaa \\
\cline{2-4}
$A_A \prec_B C_C$
& & & \\ \cline{2-4}
$A_A \mathrel{{\scriptscriptstyle\cancel{\overset{\prec}{\underset{\succ}{\approx}}}_B}} C_C$
& \cc &     & \\ \cline{2-4}
$A_A=C_C$
& \cc & \cc & \\ \cline{2-4}
$A_A \succ_B C_C$
& \cc & \cc & \\ \cline{2-4}
\end{tabularx}
\end{frame}
\end{document}

• +1 for use of mathrel ! Oct 9, 2021 at 16:10

With use of the scalebox (defined in the adjustbox package) and tabularay package:

\documentclass{beamer}
\usepackage{cancel}
\usepackage{xcolor}
\usepackage{tabularray} % tested with version 2021P

\begin{document}

\begin{frame}
\frametitle{Title}
\begin{tblr}{colspec={Q[r,$] *3{X[c]}}, % or Q[r,mode=math] hline{2-Z}={2-Z}{solid}, vline{2-Z}={2-Z}{solid}, row{2-Z} = {ht=4ex} } & aaaaaaaaaa & aaaaaaaaa & aaaaaaaaaaaaa \\ A_A \prec_B C_C & & & \\ A_A \scalebox{0.7}{$\cancel{\overset{\prec}{\underset{\succ}{\approx}}}$}_B C_C & \SetCell{gray!50} & & \\ A_A=C_C & \SetCell{gray!50} & \SetCell{gray!50} & \\ A_A \succ_B C_C & \SetCell{gray!50} & \SetCell{gray!50} & \\ \end{tblr} \end{frame} \end{document} Edit (1): Now columns 2 - 4 have equal width (and height). Edit (2): If you use Overleaf, you need to load/install the package tabularrray and ninecolors (which is requiewd by taabularray) yourself. Since I'm not familiar with Overleaf, I can't advice you, how to do this, but their support is very friendly and and they will be happy to help you with that. Also you not need to use adjustbox package if for math expression in the second row use suggestion in the @Mico answer: \documentclass{beamer} \usepackage{cancel} \usepackage{xcolor} \usepackage{tabularray} % tested with version 2021P \begin{document} \begin{frame} \frametitle{Title} \begin{tblr}{colspec={Q[r,$] *3{X[c]}}, % or Q[r,mode=math]
hline{2-Z}={2-Z}{solid},
vline{2-Z}={2-Z}{solid},
row{2-Z} = {ht=4ex}
}
& aaaaaaaaaa            & aaaaaaaaa         & aaaaaaaaaaaaa \\
A_A \prec_B C_C &                       &                   &               \\
A_A \mathrel{\scriptstyle\cancel{\overset{\prec}{\underset{\succ}{\approx}}}_B} C_C % adopted from @Mico suggestion
& \SetCell{gray!50}     &                   &               \\
A_A=C_C         & \SetCell{gray!50}     & \SetCell{gray!50} &               \\
A_A \succ_B C_C & \SetCell{gray!50}     & \SetCell{gray!50} &               \\
\end{tblr}
\end{frame}

\end{document}


• if you like to add some (complete) rows below existing, then just write it, as I did in MWE below (I don't know what is content of this row)
• if you only like have multiline content of particular cell, than yo add this text to this cell:
• in case that text is long enough, it will break in X column types into two lines automatically, for example new text aaaaaaaaa
• if it is shorter, than you need to break it manually, for example new\\ aaaaaaaaa
\documentclass{beamer}
\usepackage{cancel}
\usepackage{xcolor}
\usepackage{tabularray} % tested with version 2021P

\begin{document}

\begin{frame}
\frametitle{Title}
\begin{tblr}{colspec={Q[r,\$] *3{X[c,b]}}, % or Q[r,mode=math]
hline{2-Z}={2-Z}{solid},
vline{2-Z}={2-Z}{solid},
row{2-Z} = {ht=4ex}
}
& aaaaaaaaaa            & new text
aaaaaaaaa
& aaaaaaaaaaaaa \\
A_A \prec_B C_C &                       &                   &               \\
A_A \mathrel{\scriptstyle\cancel{\overset{\prec}{\underset{\succ}{\approx}}}_B} C_C % adopted from @Mico suggestion
& \SetCell{gray!50}     &                   &               \\
A_A=C_C         & \SetCell{gray!50}     & \SetCell{gray!50} &               \\
A_A \succ_B C_C & \SetCell{gray!50}     & \SetCell{gray!50} &               \\
A_A \nprec_B C_C    & \SetCell{gray!50} & \SetCell{gray!50} & \SetCell{gray!50}              \\
\end{tblr}
\end{frame} I tested all the examples with the latest MiKTEX program. The compilation was without warnings or errors. If you use Overleaf (as I concluded from one of your comment to other answers) then you may have problems with compilation. In this case please contact their support team and ask for help.

I allowed myself to add an overleaf tag to your question that you will get their attention.

• Thanks! I am trying to add one more row above the current one which only contains text above the second aaaa; and one more row below the current one which only contains text below A_A \succ_B C_C. I feel that your answer is the one which is most friendly to this modification. But I cannot even compile your original code. I downloaded the tabularray file. But there are many errors including "Two \documentclass or \documentstyle commands." Oct 10, 2021 at 3:58
• @Ypbor, see addendum to answer, if I understood your comment correctly. Oct 10, 2021 at 6:03