1

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}{>{\raggedright\arraybackslash}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
\setlength\tabcolsep{1pt}
  \begin{table} [htp]
    \setcellgapes{4pt}
    \centering
    \makegapedcells
    \setlength\tabcolsep{2pt}
\begin{tabularx}{\linewidth}
{| L L| 
p{0.18\textwidth} |
p{0.18\textwidth} | 
}  
  \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}
3
  • 1
    Don't place one table environment inside of a second table environment.
    – leandriis
    Jun 22, 2020 at 5:30
  • 1
    Sorry, but why bother closing a post with answers? You may have one or two legit reasons to do so; but newcomers see the hostility.
    – Symbol 1
    Nov 22, 2020 at 1:00
  • 1
    Any news? You receive three answers, does no one solve your problem? Does no one is worth to be upvoted or even accepted?
    – Zarko
    Aug 16, 2021 at 5:38

4 Answers 4

2
\documentclass[twocolumn]{svjour3}  
\usepackage{graphicx}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}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

2
  • I want to use textwidth
    – stevGates
    Jun 22, 2020 at 0:36
  • 1
    You mean the table width equal the width of both columns of the paper?
    – AboAmmar
    Jun 22, 2020 at 0:37
1
\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.1\textwidth}|p{0.1\textwidth}|c|c|}
1

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}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\usepackage{hhline, % new
            multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}  % new

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

\begin{document}
    \begin{table} [htp]
    \centering
    \setlength\tabcolsep{2pt}
\begin{tabularx}{\linewidth}{| 0{L} | 0{L}| *{2}{0{p{0.15\textwidth}} |}}
    \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}
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .