答案1
这是一个具有新I
列类型的解决方案,p
即进入和离开单元格时会进入和离开itemize
具有适当参数的环境的列,这样您只需键入您的项目即可。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{ragged2e}
\usepackage{array, tabularx}
\usepackage{makecell}
\setcellgapes{3pt}
\newcolumntype{I}[1]{>{\arraybackslash\itemize[wide=0pt, leftmargin=*, nosep, itemsep=0pt, before=\leavevmode\vspace{-\baselineskip}, after=\vspace*{-\baselineskip}]}p{0.3\linewidth}<{\enditemize}}
\begin{document}
\begin{table}[!htb]
\sffamily\makegapedcells
\begin{tabularx}{\linewidth}{|*{2}{>{\RaggedRight\arraybackslash}X|}I{\0.333\linewidth}|}
\hline
\multicolumn{2}{|c|}{XXX} & \multicolumn{1}{c|}{X} \\
\hline
A & A1 & \item A1.1
\item A1.2
\item A1.3 \\
\cline{2-3}
& A2 & \item A2 \\
\cline{2-3}
& A3 & \item A3 \\
\hline
B & B1 & \item B1.1
\item B1.2
\item B1.3 \\
\cline{2-3}
& B2 & \item B2.1%
\item B2.2%
\\
\cline{2-3}
& B3 & \item B3.1
\item B3.2\\
\cline{2-3}
& B4 & \item B4 \\
\cline{2-3}
& B5 & \item B5 \\
\cline{2-3}
& B6 & \item B6 \\
\hline
C & C1 & \item C1.1
\item C1.2 \\
\cline{2-3}%
& C1 & \item C2.1
\item C2.2 \\
\hline
\end{tabularx}
\end{table}
\end{document}
编辑:
下面是一个变体代码,可以满足您的最后要求(并添加一些花哨的东西):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{enumitem}
\usepackage{ragged2e}
\usepackage{array, tabularx, ltablex, booktabs}%
\keepXColumns
\usepackage{makecell}
\usepackage[table, svgnames]{xcolor}
\setcellgapes{3pt}
\usepackage{enumitem, etoolbox}
\AtBeginEnvironment{table}{\setlist[itemize, 1]{wide=0pt, leftmargin= *, topsep=0pt, itemsep=0pt, labelsep=.333em,
before=\leavevmode\vspace*{-\baselineskip},after=\vspace*{-\baselineskip}}}
\newcolumntype{L}{ >{\itemize}X<{\enditemize}}
\newcolumntype{I}[1]{>{\arraybackslash\itemize[wide=0pt, leftmargin=*, nosep, itemsep=0pt, before=\leavevmode\vspace{-\baselineskip}, after=\vspace*{-\baselineskip}]}p{0.3\linewidth}<{\enditemize\leavevmode}}
\begin{document}
\begin{table}[!htb]\noindent%\centering
\sffamily\makegapedcells\arrayrulecolor{IndianRed}
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\begin{tabularx}{1.07\linewidth}{!{\color{IndianRed}\vrule width 1.5pt}>{\RaggedRight\arraybackslash\hsize=0.6\hsize}X !{\color{IndianRed}\vrule width \heavyrulewidth}>{\RaggedRight\arraybackslash\hsize=1.\hsize}X%
!{\color{IndianRed}\vrule width \heavyrulewidth}>{\RaggedRight\arraybackslash\hsize=1.4\hsize}L!{\color{IndianRed}\vrule width1.5pt}}
\toprule[1.5pt]
\multicolumn{2}{!{\color{IndianRed}\vrule width 1.5pt}c !{\color{IndianRed}\vrule width \heavyrulewidth}}{XXX} & \multicolumn{1}{c!{\color{IndianRed}\vrule width 1.5pt}}{X} \\
\midrule[\heavyrulewidth]
A & A1 &
\item A1.1
\item A1.2
\item A1.3
\\%
\cline{2-3}
& A2 & \item A2 \\
\cline{2-3}
& A3 & \item A3 \\
\midrule[\heavyrulewidth]
B & B1 & \item B1.1
\item B1.2
\item B1.3 \\
\cline{2-3}
& B2 & \item B2.1%
\item B2.2%
\\
\cline{2-3}
& B3 & \item B3.1
\item B3.2\\
\cline{2-3}
& B4 & \item B4 \\
\cline{2-3}
& B5 & \item B5 \\
\cline{2-3}
& B6 & \item B6 \\
\midrule[\heavyrulewidth]
C & C1 & \item C1.1
\item C1.2 \\
\cline{2-3}%
& C1 & \item C2.1
\item C2.2 \\
\bottomrule[1.5pt]
\end{tabularx}
\end{table}
\end{document}
答案2
要让 LaTeX 自动计算列宽,您需要类似tabularx
提供类型列的包X
。
要使单元格跨越多行,您可以使用multirow
包。
为了获得更漂亮、更专业的表格,请使用该booktabs
包。
要获取表中的紧凑逐项列表,可以使用paralist
包
\usepackage{paralist}
...
\begin{compactitem}
\item ...
\item ...
...
\end{compactitem}
或enumitem
包:
\usepackage{enumitem}
\newenvironment{compactitem}%
{\begin{itemize}[nosep]}%
{\end{itemize}}
...
\begin{compactitem}
\item ...
\item ...
...
\end{compactitem}
这是传统外观(=过度使用垂直线)的表格草图,其下方有代码。之后,你会发现一个带有booktabs
、不带垂直线的版本。
\documentclass{article}
\usepackage{tabularx,multirow}
\usepackage{enumitem}
\newenvironment{compactitem}%
{\begin{itemize}[nosep]}%
{\end{itemize}}
%\usepackage{paralist}
\newcommand\sometext
{sdf dfsdf sdfsdf s df sdfsdf sdfsdsdf sdf s.
sdf dfsdf sdfsdf s df sdfsdf sdfsdsdf sdf s.
}
\begin{document}
\noindent
\begin{tabularx}{1.0\linewidth}{|X|X|X|}
\hline
\multicolumn{2}{|c|}{XXX}
& \multicolumn{1}{c|}{YYY}
\\\hline
\multirow{3}{=}{A \sometext \sometext \sometext}
& A1 \sometext
& \begin{compactitem}
\item A1.1
\item A1.2
\item A1.3
\end{compactitem}
\\\cline{2-3}
& A2 \sometext
& \begin{compactitem}
\item A2
\end{compactitem}
\\\cline{2-3}
& A3 \sometext
& \begin{compactitem}
\item A3
\end{compactitem}
\\\hline
\multirow{2}{=}{B \sometext \sometext \sometext}
& B1 \sometext
& \begin{compactitem}
\item B1.1
\item B1.2
\item B1.3
\end{compactitem}
\\\cline{2-3}
& B2 \sometext
& \begin{compactitem}
\item B2.1
\item B2.2
\end{compactitem}
\\[11.5ex]\hline
\end{tabularx}
\end{document}
\documentclass{article}
\usepackage{tabularx,multirow,booktabs}
\usepackage{enumitem}
\newenvironment{compactitem}%
{\begin{itemize}[nosep]}%
{\end{itemize}}
%\usepackage{paralist}
\newcommand\sometext
{sdf dfsdf sdfsdf s df sdfsdf sdfsdsdf sdf s.
sdf dfsdf sdfsdf s df sdfsdf sdfsdsdf sdf s.
}
\begin{document}
\noindent
\begin{tabularx}{1.0\linewidth}{XXX}
\toprule
\multicolumn{2}{c}{XXX}
& \multicolumn{1}{c}{YYY}
\\\midrule
\multirow{3}{=}{A \sometext \sometext \sometext}
& A1 \sometext
& \begin{compactitem}
\item A1.1
\item A1.2
\item A1.3
\end{compactitem}
\\\cmidrule{2-3}
& A2 \sometext
& \begin{compactitem}
\item A2
\end{compactitem}
\\\cmidrule{2-3}
& A3 \sometext
& \begin{compactitem}
\item A3
\end{compactitem}
\\\midrule
\multirow{2}{\linewidth}{B \sometext \sometext \sometext}
& B1 \sometext
& \begin{compactitem}
\item B1.1
\item B1.2
\item B1.3
\end{compactitem}
\\\cmidrule{2-3}
& B2 \sometext
& \begin{compactitem}
\item B2.1
\item B2.2
\end{compactitem}
\\[11.5ex]\bottomrule
\end{tabularx}
\end{document}
答案3
你可以从这样的事情开始:
\documentclass[12pt,a4paper]{article}
\usepackage{enumitem, tabularx}
\begin{document}
\setlist[itemize]{leftmargin = *, itemsep=-3pt,
before=\vspace*{-\dimexpr\baselineskip+\partopsep},
after=\vspace*{\dimexpr-\baselineskip+\partopsep}}
\begin{tabularx}{\linewidth}{|*3{X|}}
\hline
\multicolumn{2}{|c|}{XXX} & YYY \\ \hline
A & A1 & \begin{itemize}
\item A1.1
\item A1.2
\item A1.3
\end{itemize} \\ \cline{2-3}
& A2 & A2 \\ \cline{2-3}
& A3 & A3 \\ \hline
B & B1 & \begin{itemize}
\item B1.1
\item B1.2
\item B1.3
\end{itemize} \\ \cline{2-3}
& B2 & ? B2.1 \\ \cline{2-3}
& B3 & ? B3.1 \\ \cline{2-3}
& B4 & ? B4 \\ \cline{2-3}
& B5 & ? B5 \\ \cline{2-3}
& B6 & ? B6 \\ \hline
C & Cl & Cl.l \\
& & \\ \cline{2-3}
& C2 & C2.1 \\
& & \\ \hline
\end{tabularx}
\end{document}