考虑以下 MWE:
\documentclass[letterpaper]{article}
\usepackage[letterpaper,top=2.5cm,bottom=2.5cm,lmargin=2.5cm,rmargin=2.5cm]{geometry}
\usepackage{array,booktabs,tabularx}
\usepackage{ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.25}
\begin{tabularx}{\textwidth}{*{3}{L}}
\hline
\textbf{Sample Test Sample} & \textbf{Sample Test Sample} & \textbf{Sample Test Sample Sample Test Sample}%
\\\hline%
\begin{itemize}%
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\end{itemize}%
&
\begin{itemize}%
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\end{itemize}%
&
\begin{itemize}%
\item Sample Test Sample
\item Sample Test Sample
\end{itemize}%
\\\hline
\end{tabularx}
\end{center}
\end{document}
我怎样才能仅使用垂直居中第一行tabularx
,并且如果可能的话删除多余的垂直空间,如图所示?
答案1
我怎样才能垂直居中仅限第一行使用
tabularx
...[强调]
我建议您\multicolumn{1}
对标题行中的第三个单元格使用“包装器”。下面发布的代码中提供了更多详细信息。
我怎样才能...删除图表中显示的额外垂直空间?
我建议你使用枚举项包并使用其\newlist
和\setlist
宏来定义一个类似于 itemize 的环境,该环境可自动抑制多余的空格。在下面的代码中,此环境被称为tabitemize
。通过定义这样一个定制环境,基本环境的属性itemize
保持不变。
\documentclass{article}
\usepackage[letterpaper,margin=2.5cm]{geometry}
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{M}[1]{>{\RaggedRight}m{#1}} % use 'm' column type
\usepackage{enumitem} % for '\newlist' and '\setlist' macros
% use '\newlist' and '\setlist' to define a new itemize-like env.:
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,left=0pt,noitemsep,
before={\begin{minipage}[t]{\hsize}},
after ={\end{minipage}}}
\newlength\mylen
\setlength\mylen{\dimexpr0.333\textwidth-1.333\tabcolsep\relax}
\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.25}
\begin{tabularx}{\textwidth}{@{} LLL @{}} % no whitespace padding at the edges
\toprule
\textbf{Sample Test Sample} & \textbf{Sample Test Sample} &
\multicolumn{1}{M{\mylen}}{\textbf{Sample Test Sample Sample Test Sample}}\\
\midrule
\begin{tabitemize}
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\end{tabitemize}
&
\begin{tabitemize}
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\end{tabitemize}
&
\begin{tabitemize}
\item Sample Test Sample
\item Sample Test Sample
\end{tabitemize}
\\
\bottomrule
\end{tabularx}
\end{center}
\end{document}
答案2
如果你愿意使用tabullarray
包而不是tabularx
,MWE 会更简单和更短,但编译时间会更长:
\documentclass[letterpaper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{lipsum}
\usepackage{microtype}
\usepackage{ragged2e}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, varwidth}
\usepackage{enumitem}
\begin{document}
\begin{center}
\setlist[itemize]{nosep, leftmargin=*}
\begin{tblr}{colspec = {@{} *{3}{X[cmd=\RaggedRight\hspace{0pt}]} @{}},
row{1} = {font=\bfseries, m},
stretch=-1,%<--- remove extra space above and below lists
% with nosep option; see doc p.51 tabularray
measure = vbox,
row{3-Z} = {rowsep=5pt}
}
\toprule
Sample Test Sample
& Sample Test Sample
& Sample Test Sample Sample Test Sample \\
\midrule
\begin{itemize}
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\end{itemize}
& \begin{itemize}
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\end{itemize}
& \begin{itemize}
\item Sample Test Sample
\item Sample Test Sample
\end{itemize} \\
\begin{itemize}
\item \lipsum[1][1-2]
\item \lipsum[1][3-5]
\end{itemize}
& \begin{itemize}
\item \lipsum[1][1-2]
\item \lipsum[1][3-5]
\end{itemize}
& \begin{itemize}
\item \lipsum[1][1-2]
\item \lipsum[1][3-5]
\end{itemize} \\
\bottomrule
\end{tblr}
\end{center}
\end{document}