TransWikia.com

How to use multirow in multicolumn to merge a tabularx cell

TeX - LaTeX Asked on November 16, 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

enter image description here

I wont change the structure of my code and the width of my table :

documentclass[twocolumn]{svjour3}  
usepackage{graphicx}
usepackage{makecell, multirow, tabularx}
newcolumntype{L}{>{raggedrightarraybackslash}X}  % new
usepackage{enumitem}                               % new
newlist{tabitem}{itemize}{1}   % <-- defined new list
setlist[tabitem]{nosep,        % <-- new list setup
                  leftmargin=*,
                  label=$bullet$,
                  before=begin{minipage}[t]{linewidth}, 
                  after=end{minipage}                   
                  }


begin{table} [htp]
setcellgapes{2pt}
centering
makegapedcells
setlengthtabcolsep{1pt}
  begin{table} [htp]
    setcellgapes{4pt}
    centering
    makegapedcells
    setlengthtabcolsep{2pt}
begin{tabularx}{linewidth}
{| L L| 
p{0.18textwidth} |
p{0.18textwidth} | 
}  
  hline
  
  multicolumn{2}{c}{ multirow{2}{=} {centering A}}  & 
   multirow{2}{=} {centering TextTextText} &  
   multirow{2}{=} {centering TextTextText}           
            
              \ 
    hline
    
    
      hline
  
  multicolumn{2}{c}{ {centering MADM}}  & 
   multirow{2}{=} {centering T} &  
   multirow{2}{=} {centering T}           
            
              \ 
    hline
    
    

    
  end{tabularx}
  end{table}

4 Answers

With {NiceTabularX} of nicematrix (≥ 6.0).

documentclass[twocolumn]{svjour3}   
usepackage{graphicx}
usepackage{nicematrix}

begin{document}

renewcommand{arraystretch}{1.4}
noindent
begin{NiceTabularX}{linewidth}{llXX}[hvlines,colortbl-like]
Block[l]{1-2}{A}    && TexttEXTtext    & TextTextText \
Block[l]{1-2}{MADM} && T & T \
Block{2-1}{AAAA}    & Block{2-1}{AAA} & T & T \
                     &                  & cellcolor{yellow!30} T & T 
end{NiceTabularX}

end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

Answered by F. Pantigny on November 16, 2021

documentclass{scrartcl}
usepackage{makecell, multirow, tabularx}
usepackage[table,dvipsnames]{xcolor}
usepackage{color, colortbl}

begin{document}

begin{table}[htbp!]
    centering
    caption{Caption}
    label{tab:my_label}
    begin{tabular}{|l|l|c|c|}
    hline
        multicolumn{2}{|c|}{A} & TextTextText & TextTextText \
    hline
        multicolumn{2}{|c|}{MADM} & T & T \
    hline
        multirow{2}{*}{AAA} & multirow{2}{*}{AAA} & T & T \
    cline{3-4}
        & & cellcolor{yellow!50} T & T \
    hline
    end{tabular}
end{table}
end{document}

yields

enter image description here

If you would like to specify the width, you can consider modifying, for ex., as below:

    begin{tabular}{|p{0.1textwidth}|p{0.1textwidth}|c|c|}

Answered by fromthebeeland on November 16, 2021

documentclass[twocolumn]{svjour3}  
usepackage{graphicx}
usepackage{makecell, multirow, tabularx}
newcolumntype{L}{>{raggedrightarraybackslash}X}  % new
usepackage{enumitem}                               % new
newlist{tabitem}{itemize}{1}   % <-- defined new list
setlist[tabitem]{nosep,        % <-- new list setup
                  leftmargin=*,
                  label=$bullet$,
                  before=begin{minipage}[t]{linewidth}, 
                  after=end{minipage}                   
                  }

begin{document}

begin{table}[!htp]
setcellgapes{2pt}
centering
makegapedcells
begin{tabularx}{linewidth}{|l|l|X|X|}  
hline
multicolumn{2}{|l|}{A}                                  & TextTextText & TextTextText \ hline
multicolumn{2}{|l|}{MADM}                               & T            & T            \ hline
multirow{2}{*}[-2pt]{AAAA} & multirow{2}{*}[-2pt]{AAA} & T            & T            \ cline{3-4} 
                            &                            & T            & T            \ hline
end{tabularx}
end{table}

end{document}

enter image description here

If you want a page-wide table in that two-column document, use the starred version of table (begin{table*}[!htb] .. end{table*}):

enter image description here

Answered by AboAmmar on November 16, 2021

Edit: From the preamble are removed not used package and style definition, added package hhline and improved MWE code:

enter image description here

documentclass[twocolumn]{svjour3}
usepackage{graphicx}
usepackage[column=0]{cellspace}
setlengthcellspacetoplimit{4pt}
setlengthcellspacebottomlimit{4pt}
usepackage{hhline, % new
            multirow, tabularx}
newcolumntype{L}{>{raggedrightarraybackslash}X}  % new

usepackage[table]{xcolor}  % new
usepackage{xparse}         % new
NewExpandableDocumentCommandmcl{O{1}m}
    {multicolumn{#1}{|c|}{#2}}

begin{document}
    begin{table} [htp]
    centering
    setlengthtabcolsep{2pt}
begin{tabularx}{linewidth}{| 0{L} | 0{L}| *{2}{0{p{0.15textwidth}} |}}
    hline
mcl[2]{A}  &  TextTextText &  TextTextText \
    hline
mcl[2]{MADM}
            &   T           &   T           \
    hline 
multirow{2}{=}{AAAA}
    &   multirow{2}{=}{AAA}   
            &   T           &   T           \
    hhline{|~|~|-|-|}
    &   mcl[1]{}   
            & cellcolor{yellow!30}{T}
                            &   T           \
    hline
end{tabularx}
    end{table}
end{document}

Answered by Zarko on November 16, 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