TransWikia.com

How to use multi-row and multi-column with textwidth in latex?

TeX - LaTeX Asked on February 9, 2021

I used a code, I have a table which created by using tabularx, but the problem is that, I want to create that following table by using tabularx and using textwidth, where the value of the first column A is 0.1/5, the column TexttExText is 0.2/5 and TextTextText is 0.2/5.
I want activate the auto break line.
I wanna created a table like that :

enter image description here

I start creating that code:

documentclass[twocolumn]{svjour3}

usepackage{ragged2e}
usepackage{makecell, multirow, tabularx}
newcolumntype{L}{>{RaggedRight}X}


begin{document}  
     begin{table} 
        setcellgapes{4pt}
        centering
        makegapedcells
        setlengthtabcolsep{2pt}
    begin{tabularx}{columnwidth}{
    |>{hsize =0.5hsize}L
    |>{hsize =0.5hsize}L
    |>{hsize =1.5hsize}L
    |>{hsize =1.5hsize}L| }
      hline
    multicolumn{2}{|c|}{ 
    multirowcell{1}{centering TextText1}
    } &
       multirowcell{1}{centering TextText2} &
        multirowcell{1}{centering TextText3} 
     hline
    
    
     hline
      multirow{2}{=} { A1A1} & 
     AAA & 
     T & 
     T 
     
     
     & A2 & A & A
     hline
    
    
      end{tabularx}
      end{table}


end{document}

2 Answers

Here is what you can do with {NiceTabular} of nicematrix (≥ 4.0 2020-05-08).

documentclass{article}

usepackage{nicematrix}

newcolumntype{P}[1]{>{raggedrightarraybackslash}p{#1textwidth}}

begin{document}

begin{NiceTabular}{P{0.1}P{0.1}P{0.4}P{0.4}}[hvlines]
Block{1-2}{TextText1} & & Block{1-1}{TextText2} & Block{1-1}{TextText3} 
A1A1 Block{1-2}{} & 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
A2A2  Block{1-2}{} & 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
Block{3-1}{rotate Machine learning} 
& Aaa1 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
& Aaa2 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
& Aaa2 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
& TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
end{NiceTabular}

end{document}

Outuput of the above code

Answered by F. Pantigny on February 9, 2021

With tabularx (needed only one compilation for final result):

Edit:

IN original answer was used article document class. Changing it to [twocolumn]{svjour3} doesn't influence on MWE compilation. However, table is limited to one column only i.e. it become to narrow to be nice:

enter image description here

(to obtain this result you need to use table float, font size small and change multirow cell specification to multirow{23}{=}{centeringrotatebox{90}{Machine learning}})

Nicer result (to my opinion) you can get with use of the table* float environment:

documentclass{article}
usepackage{graphicx}
usepackage{makecell, multirow, tabularx}
renewcommandtheadfont{smallbfseries}
renewcommandtheadgape{}
newcolumntype{L}[1]{>{raggedrightarraybackslashhsize=#1hsize}X}
newcommandmcxx[1]{multicolumn{2}%
                                {|>{hsize=dimexprhsize+2tabcolsep+arrayrulewidth}X|}%
                                {#1}}

begin{document}
    begin{table}[ht]
    setcellgapes{4pt}
    makegapedcells
begin{tabularx}{linewidth}{ |*{2}{L{0.5}|} *{2}{L{1.5}|} }
    hline
mcxx{thead{TextText1}}   
        & thead{TextText2} & thead{TextText3} 
    hline
mcxx{A1A1}
        & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT
            & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
    hline
mcxx{A2A2}
        & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT
            & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
    hline
multirow{14}{=}{hfilrotatebox{90}{Machine learning}}
    & Aaa1
        & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT
            & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
    cline{2-4}
    & Aaa2
        & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT
            & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
    cline{2-4}
    & Aaa3
        & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT
            & TextTexT1 TextTex T1 TextTexT1 Text Text1 Text TexT1 TextTexT1 Text TexT TextTexT 
    hline
end{tabularx}
    end{table}
end{document}

enter image description here

Answered by Zarko on February 9, 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