我怎样才能绘制这个表 1?

我怎样才能绘制这个表 1?

如何在 LaTeX 中绘制下表?

我可以像下图一样在表格中添加项目吗?

在此处输入图片描述

我尝试了这个代码:

\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}

答案1

在此处输入图片描述

您的代码示例与您想要获得的结果相差甚远……

\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}

如果表格的第一行只有一行文本,则可以将该行写为:

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

编辑: 当您有更多带有单元格列表的表格时,您可以使用\AtBeginEnvironment包中的宏etoolbox并将列表设置从浮动环境移动centertable文档序言:

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

附录:

我永远不会给自己买这样的桌子。我更喜欢这样的:

在此处输入图片描述

\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}

答案2

以下重现了表格的外观。您必须调整\dimexpr5em+1cm+1cm+6\tabcolsep\relax以匹配表格的宽度。每列需要两个\tabcolsep加上每列的宽度。

\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}

在此处输入图片描述

相关内容