我对以下问题感兴趣我怎样才能绘制这个表 1?
我想知道如何在表格中的“itemize”中使用 itemize 我尝试了@Zarko 的代码,但没有成功,此外,我想知道为什么我无法获得灰色标题部分周围的所有 4 个边框
\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}
答案1
根据我对这个问题的回答我怎样才能画出这张表 1:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{center}{%
\setlist[itemize,1]{nosep,
topsep = 0pt,
partopsep = 0pt,
leftmargin = *,
label = \textendash,
before = \vspace{-0.6\baselineskip},
after = \vspace{-\baselineskip}
}
\setlist[itemize]{ nosep,
leftmargin=*,
label = $\bullet$
} }
\begin{document}
\begin{center}
\bfseries
\begin{tabularx}{\linewidth}{ | l | X | }
\hline
\multicolumn{2}{|>{\centering\arraybackslash}%
p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth\relax}|}{\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
\begin{itemize}
\item long text bla bla bla bla
\item long text bla bla bla bla
\end{itemize}
\end{itemize} \\
\hline
Addition & long text bla bla bla bla long text bla bla bla bla\\
\hline
\end{tabularx}
\end{center}
\end{document}
答案2
下面是带有嵌套 itemize 的代码,以及各种改进和简化:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[table, svgnames]{xcolor}
\usepackage{tabularx, hhline}
\usepackage{enumitem}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\renewcommand{\tabularxcolumn}[1]{ >{\arraybackslash\compress}p{#1}}
\begin{document}
\begin{center}
\setlist[itemize]{wide=0pt, nosep, leftmargin= * }
\setlist[itemize, 1]{ label=\textendash, after=\vspace{-\baselineskip}}
\setlist[itemize, 2]{ label=\textgreater}
\setlength{\doublerulesep}{12pt}
\setlength{\extrarowheight}{2pt}
\bfseries
\begin{tabularx}{\linewidth}{ | l | X | }
\hhline{--}
\rowcolor{WhiteSmoke!70!Lavender}\multicolumn{2}{|>{\centering\arraybackslash}p{\dimexpr\linewidth-2\tabcolsep}|}{%
Very long text here and centered
Very long text here and centered
Very long text here and centered} \\
% \hline \noalign{\vspace*{12pt}}
%\multicolumn{2}{c}{} \\
\hhline{==}
Description & \begin{itemize}
\item long text bla bla bla bla
\item long text bla bla bla bla
\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}
\item long text bla bla bla bla
\item long text bla bla bla bla
\end{itemize} \\
\hhline{--}
Addition & long text bla bla bla bla long text bla bla bla bla\\
\hhline{--}
\end{tabularx}
\end{center}
\end{document}
答案3
第一个表不包括
before
和after
选项,以便纠正itemize
环境上方和下方的间距。第二个表格包括这些选项。正如我们所见,负数
vspace
s 会干扰嵌套itemize
环境,因为它们会累加。第三个表格再次不包含
before
和after
选项,但包括一些手动调整,以摆脱第一级itemize
环境上方和下方不必要的空白。
\documentclass{article}
\usepackage[utf8]{inputenc}
\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}
}
\begin{tabularx}{\linewidth}{ | l | X | }
\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
\begin{itemize}
\item short text
\item short text
\end{itemize}
\end{itemize} \\
\hline
Addition & long text bla bla bla bla long text bla bla bla bla\\
\hline
\end{tabularx}
\end{center}
\begin{center}
\setlist[itemize]{nosep,
topsep= 0pt,
partopsep=0pt,
leftmargin= *,
label=\textendash,
before=\vspace{-0.6\baselineskip},
after=\vspace{-\baselineskip}
}
\begin{tabularx}{\linewidth}{ | l | X | }
\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
\begin{itemize}
\item short text
\item short text
\end{itemize}
\end{itemize} \\
\hline
Addition & long text bla bla bla bla long text bla bla bla bla\\
\hline
\end{tabularx}
\end{center}
\begin{center}
\setlist[itemize]{nosep,
topsep= 0pt,
partopsep=0pt,
leftmargin= *,
label=\textendash,
%before=\vspace{-0.6\baselineskip},
%after=\vspace{-\baselineskip}
}
\begin{tabularx}{\linewidth}{ | l | X | }
\hline
Description & \begin{itemize} \vspace{-0.6\baselineskip}
\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
\begin{itemize}
\item short text
\item short text
\end{itemize}\vspace{-\baselineskip}
\end{itemize} \\
\hline
Addition & long text bla bla bla bla long text bla bla bla bla\\
\hline
\end{tabularx}
\end{center}
\end{document}
最后一个表格也可以用以下 MWE 来生成,它使用两个不同的、新定义的环境来表示表格单元格内的itemize
第一级和后续级环境:itemize
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{enumitem}
\newlist{tabitemizefirst}{itemize}{1}
\newlist{tabitemizesecond}{itemize}{1}
\setlist[tabitemizefirst]{nosep,
topsep= 0pt,
partopsep=0pt,
leftmargin= *,
label=\textendash,
before=\vspace{-0.6\baselineskip},
after=\vspace{-\baselineskip}
}
\setlist[tabitemizesecond]{nosep,
topsep= 0pt,
partopsep=0pt,
leftmargin= *,
label=\textendash,
}
\begin{document}
\begin{tabularx}{\linewidth}{ | l | X | }
\hline
Description & \begin{tabitemizefirst}
\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
\begin{tabitemizesecond}
\item short text
\item short text
\end{tabitemizesecond}
\end{tabitemizefirst} \\
\hline
Addition & long text bla bla bla bla long text bla bla bla bla\\
\hline
\end{tabularx}
\end{document}