我有一张类似下面的表格,我想让列的内容垂直对齐。此外,第一列应水平居中,第二列应像现在这样(左对齐,因为 p{width})。如何实现这一点?我知道包参数,array
但m,b,p
我不知道如何将它们居中并同时将它们对齐。
\documentclass[11pt]{report}
\usepackage{longtable}
\usepackage{array}
\usepackage{lipsum}
\begin{document}
\begin{longtable}{ p{0.25\textwidth} | p{0.75\textwidth} }
\caption{A simple longtable example}\\
%\label{somelabelofatableusinglongtable}
\hline
\textbf{First entry} & \textbf{Second entry} \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{\textit{page}} & \textbf{\textit{Content}} \\\hline \endhead
\hline
\endhead
\hline \multicolumn{2}{r}{\textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
i & \lipsum[1].\\
& \\
\textcolor{blue}{i} & \textcolor{blue}{All grammar has been checked.} \\
& \\
\hline
N/A & \lipsum[1] \\
\end{longtable}
\end{document}
答案1
很tabularray
简单:
\documentclass[11pt]{report}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{lipsum}
\begin{document}
\begin{longtblr}[
caption={A simple longtable example},
label={somelabelofatableusinglongtable}
]{hlines,
colspec={ l | X[j] },
rowhead = 1,
cell{1}{1,2} = {c=1}{c}, % center content each 1st row,
row{1}={font=\bfseries},
}
First entry & Second entry \\
i & \lipsum[1] \\
\SetRow{fg=blue}
i & All grammar has been checked. \\*
N/A & \lipsum[1] \\
\SetRow{fg=blue}
ii & All grammar has been checked. \\*
N/A & \lipsum[1] \\
\end{longtblr}
\end{document}
tabularray
注意:从今天(9 月 7 日)开始,可以通过 MiKTeX Console 下载该软件包的 2021N 版本。使用它进行编译将得到以下结果: