3

How can I draw the following table in LaTeX?

Can I add the itemize inside the table like the image below?

Enter image description here

I tried this code:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage[utf8]{inputenc}
 \begin{document}
\begin{center}
\begin{tabular}{ | m{5em} | m{1cm}|  }
  \hline
  \rowcolor{gray!40}
  \multicolumn{2}
    {|>{\centering\arraybackslash}m{\dimexpr5em+1cm+1cm+6\tabcolsep\relax}|}
    {Very Long text here and centred}\\
  \hline
  \noalign{\vspace{1ex}}
  \hline
  Description & ong text bla bla bla bla bla bla   \\
  \hline
  Adition & long text bla bla bla bla bla bla bla bla  \\
  \hline
\end{tabular}
\end{center}
5

enter image description here

Your code example is not even close to what you like to obtain...

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage{enumitem}

\begin{document}
    \begin{center}
\setlist[itemize]{nosep,
                  topsep= 0pt,
                  partopsep=0pt,
                  leftmargin= *,
                  label=\textendash,
                  before=\vspace{-0.6\baselineskip},
                  after=\vspace{-\baselineskip}
                  }
\bfseries
\begin{tabularx}{\linewidth}{ | l | X | }
    \hline
\multicolumn{2}{|>{\centering\arraybackslash}p{\dimexpr\linewidth-2\tabcolsep}|}{\cellcolor{gray!30}
    Very long text here and centered
    Very long text here and centered
    Very long text here and centered}    \\
    \hline
\multicolumn{2}{c}{}                    \\
    \hline
Description &   \begin{itemize}
                \item   long text bla bla bla bla
                \item   long text bla bla bla bla
                \item   long text bla bla bla bla
                \item   long text bla bla bla bla
                \end{itemize}          \\
    \hline
Addition    & long text bla bla bla bla long text bla bla bla bla\\
    \hline
\end{tabularx}
    \end{center}
\end{document}

In the case that there will be only one line text in the first table row, then you can do this row write as:

\multicolumn{2}{|c|}{\cellcolor{gray!30} Very long text here and centered}    \\

Edit: in the cases when you have more tables with lists in the cells, you can use macro \AtBeginEnvironment from the package etoolbox and move list setup from center or table float environment to document preamble:

\usepackage{etoolbox}
\AtBeginEnvironment{table}{%
    \setlist[itemize,1]{nosep,     
                        topsep     = 0pt,
                        partopsep  = 0pt,
                        leftmargin = *,
                        label      = \textendash,
                        before     = \vspace{-0.6\baselineskip},
                        after      = \vspace{-\baselineskip}
                        }  }

Addendum:

I would never get such a table for myself. I prefer something like this:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{booktabs, tabularx}
\usepackage[skip=1ex,labelfont=bf,justification=centerlast]{caption}
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{table}{%
    \setlist[itemize,1]{nosep,     
                        topsep     = 0pt,
                        partopsep  = 0pt,
                        leftmargin = *,
                        label      = \textendash,
                        before     = \vspace{-0.6\baselineskip},
                        after      = \vspace{-\baselineskip}
                        }  }

\begin{document}
    \begin{table}[htb]
\caption{Very long text here and centered
    Very long text here and centered
    Very long text here and centered}
\label{tab: my table}
\begin{tabularx}{\linewidth}{ l X }
    \toprule
Description &   \begin{itemize}
                \item   long text bla bla bla bla
                \item   long text bla bla bla bla
                \item   long text bla bla bla bla
                \item   long text bla bla bla bla
                \end{itemize}          \\
    \addlinespace
Addition    & long text bla bla bla bla long text bla bla bla bla\\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}
5
  • one question please I already use itemize and when i add this code its disorder the itemize for my other work in document
    – Jabir
    Apr 17 '18 at 7:24
  • @Jabir, corrected. its definition had to be "local", in the environment where the table is placed.
    – Zarko
    Apr 17 '18 at 7:26
  • @Zarko: you should use a \textendash as a label for itemize, not a hyphen.
    – Bernard
    Apr 17 '18 at 10:41
  • @Bernard, thank you for pointing this. i will correct asap.
    – Zarko
    Apr 17 '18 at 11:22
  • @tex.stackexchange.com/questions/427064/… I'm interested of your answer would you see my question
    – Educ
    Apr 17 '18 at 17:59
4

The following reproduces the look of your table. You'll have to adjust the \dimexpr5em+1cm+1cm+6\tabcolsep\relax to match the width of your table. You'll need two \tabcolsep per column plus the width of each column.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage[utf8]{inputenc}
 \begin{document}
\begin{center}
\begin{tabular}{ | m{5em} | m{1cm}| m{1cm} | } 
  \hline
  \rowcolor{gray!40}
  \multicolumn{3}
    {|>{\centering\arraybackslash}m{\dimexpr5em+1cm+1cm+6\tabcolsep\relax}|}
    {Very Long text here and centred}\\
  \hline
  \noalign{\vspace{1ex}}
  \hline
  cell1 dummy text dummy text dummy text& cell2 & cell3 \\ 
  \hline
  cell1 dummy text dummy text dummy text & cell5 & cell6 \\ 
  \hline
  cell7 & cell8 & cell9 \\ 
  \hline
\end{tabular}
\end{center}
\end{document}

enter image description here

6
  • yes but I would like to create the exact table in image thanks
    – Jabir
    Apr 17 '18 at 7:10
  • @Jabir why do you give us an MWE with so little in common then? Your column counts don't match and the text is different, too.
    – Skillmon
    Apr 17 '18 at 7:12
  • I really appreciated your help
    – Jabir
    Apr 17 '18 at 7:20
  • @Jabir if so say it with votes.
    – Skillmon
    Apr 17 '18 at 7:22
  • 1
    @Skillmon, so far op haven't rights to vote. instead of him/her i will do this :-)
    – Zarko
    Apr 17 '18 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.