TransWikia.com

How to increase row height of first row and decrease column width of first column in the table same as the picture I want?

TeX - LaTeX Asked on January 19, 2021

I want to make table as below.

documentclass{article}
usepackage[left=4cm,right=3cm,top=4cm,bottom=3cm]{geometry}
usepackage{amsmath}
usepackage{slashbox}
begin{document}
    begin{table}[h!]
        centering
        caption{$(a_1,b_1)+(a_2,b_2)in boldsymbol{cdot}$}
        begin{tabular}{|c|c|c|c|c|c|}
            hline
            backslashbox{tabular{@{}l@{}}$(a_1,b_1)inboldsymbol{cdot} $endtabular}{$(a_2,b_2)inboldsymbol{cdot}$}&${(0,0)}$&$mathcal{A}_1$&$mathcal{A}_2$&$mathcal{A}_3$&$mathcal{A}_4$
            hline
            ${(0,0)}$&${(0,0)}$&$mathcal{A}_1$&$mathcal{A}_2$&$mathcal{A}_3$&$mathcal{A}_4$
            hline
            $mathcal{A}_1$&$mathcal{A}_1$&${(0,0)},mathcal{A}_4$&$mathcal{A}_3$&$mathcal{A}_2$&$mathcal{A}_1$
            hline
            $mathcal{A}_2$&$mathcal{A}_2$&$mathcal{A}_3$&${(0,0)},mathcal{A}_4$&$mathcal{A}_1$&$mathcal{A}_2$
            hline
            $mathcal{A}_3$&$mathcal{A}_3$&$mathcal{A}_2$&$mathcal{A}_1$&${(0,0)},mathcal{A}_4$&$mathcal{A}_3$
            hline
            $mathcal{A}_4$&$mathcal{A}_4$&$mathcal{A}_1$&$mathcal{A}_2$&$mathcal{A}_3$&${(0,0)},mathcal{A}_4$
            hline
        end{tabular}
        label{tabelbukti15}
    end{table}
end{document}

The result is

enter image description here

Now, I want to increase row height of first row and decrease column width of first column like this picture:
enter image description here

I have tried use this code

documentclass{article}
usepackage[left=4cm,right=3cm,top=4cm,bottom=3cm]{geometry}
usepackage{amsmath}
usepackage{slashbox}
begin{document}
    begin{table}[h!]
        centering
        caption{$(a_1,b_1)+(a_2,b_2)in boldsymbol{cdot}$}
        begin{tabular}{|p{3cm}|c|c|c|c|c|}
            hline
            backslashbox{tabular{@{}l@{}}$(a_1,b_1)inboldsymbol{cdot} $endtabular}{$(a_2,b_2)inboldsymbol{cdot}$}&${(0,0)}$&$mathcal{A}_1$&$mathcal{A}_2$&$mathcal{A}_3$&$mathcal{A}_4$[1cm]
            hline
            ${(0,0)}$&${(0,0)}$&$mathcal{A}_1$&$mathcal{A}_2$&$mathcal{A}_3$&$mathcal{A}_4$
            hline
            $mathcal{A}_1$&$mathcal{A}_1$&${(0,0)},mathcal{A}_4$&$mathcal{A}_3$&$mathcal{A}_2$&$mathcal{A}_1$
            hline
            $mathcal{A}_2$&$mathcal{A}_2$&$mathcal{A}_3$&${(0,0)},mathcal{A}_4$&$mathcal{A}_1$&$mathcal{A}_2$
            hline
            $mathcal{A}_3$&$mathcal{A}_3$&$mathcal{A}_2$&$mathcal{A}_1$&${(0,0)},mathcal{A}_4$&$mathcal{A}_3$
            hline
            $mathcal{A}_4$&$mathcal{A}_4$&$mathcal{A}_1$&$mathcal{A}_2$&$mathcal{A}_3$&${(0,0)},mathcal{A}_4$
            hline
        end{tabular}
        label{tabelbukti15}
    end{table}
end{document}

And the result is not as expected.

enter image description here

How to increase row height of first row and decrease column width of first column in the table same as the picture I want?

2 Answers

Here is a solution with the package nicematrix which provides a built-in command diagbox in its environments {NiceTabular} and {NiceArray}.

documentclass{article}
usepackage[left=4cm,right=3cm,top=4cm,bottom=3cm]{geometry}
usepackage{amsmath}
usepackage{nicematrix}
begin{document}
begin{table}[h!]
centering
caption{$(a_1,b_1)+(a_2,b_2)in boldsymbol{cdot}$}
renewcommand{arraystretch}{1.4}
[begin{NiceArray}{wc{3cm}ccccc}[hvlines]
    rule[-4mm]{0pt}{1.1cm}
    diagbox{(a_1,b_1)inboldsymbol{cdot}}{(a_2,b_2)inboldsymbol{cdot}}&{(0,0)}&mathcal{A}_1&mathcal{A}_2&mathcal{A}_3&mathcal{A}_4
    {(0,0)}&{(0,0)}&mathcal{A}_1&mathcal{A}_2&mathcal{A}_3&mathcal{A}_4
    mathcal{A}_1&mathcal{A}_1&{(0,0)},mathcal{A}_4&mathcal{A}_3&mathcal{A}_2&mathcal{A}_1
    mathcal{A}_2&mathcal{A}_2&mathcal{A}_3&{(0,0)},mathcal{A}_4&mathcal{A}_1&mathcal{A}_2
    mathcal{A}_3&mathcal{A}_3&mathcal{A}_2&mathcal{A}_1&{(0,0)},mathcal{A}_4&mathcal{A}_3
    mathcal{A}_4&mathcal{A}_4&mathcal{A}_1&mathcal{A}_2&mathcal{A}_3&{(0,0)},mathcal{A}_4
end{NiceArray}]
label{tabelbukti15}
end{table}
end{document}

You need several compilations (because niceamtrix uses PGF/Tikz nodes).

Output of the above code

Correct answer by F. Pantigny on January 19, 2021

I wouldn't use slashbox, instead it I would rather redesign your table as follows:

documentclass{article}
usepackage[hmargin={4cm,3cm}, vmargin={4cm,3cm}]{geometry}
usepackage{amsmath}
usepackage[table]{xcolor}

begin{document}
    begin{table}[h!]
caption{$(a_1,b_1)+(a_2,b_2)in boldsymbol{cdot}$}
        label{tabelbukti15}
    centering
    renewcommandarraystretch{1.5}
    vskip-abovedisplayskip
[
begin{array}{|*{6}{c|}}
    hline
    & multicolumn{5}{c|}{(a_2,b_2)inbullet}   
    cline{2-6}
(a_2,b_2)inbullet
    &   {(0,0)}
        &   mathcal{A}_1
            &   mathcal{A}_2
                &   mathcal{A}_3
                    &   mathcal{A}_4           
    hline
{(0,0)}
    &   cellcolor{gray!30}{{(0,0)}}
        &   mathcal{A}_1
            &   mathcal{A}_2
                &   mathcal{A}_3
                    &   mathcal{A}_4           
            hline
mathcal{A}_1
    &   mathcal{A}_1
        &   cellcolor{gray!30}{{(0,0)},mathcal{A}_4}
            &   mathcal{A}_3
                &   mathcal{A}_2
                    &   mathcal{A}_1           
    hline
mathcal{A}_2
    &   mathcal{A}_2
        &   mathcal{A}_3
            &   cellcolor{gray!30}{{(0,0)},mathcal{A}_4}
                &   mathcal{A}_1
                    &   mathcal{A}_2           
    hline
mathcal{A}_3
    &   mathcal{A}_3
        &   mathcal{A}_2
            &   mathcal{A}_1
                &   cellcolor{gray!30}{{(0,0)},mathcal{A}_4}
                    &   mathcal{A}_3           
    hline
mathcal{A}_4
    &   mathcal{A}_4
        &   mathcal{A}_1
            &   mathcal{A}_2
                &   mathcal{A}_3
                    &   cellcolor{gray!30}{{(0,0)},mathcal{A}_4}

    hline
end{array}
]
    end{table}
end{document}

enter image description here

Answered by Zarko on January 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP