![如何在同一行中使用不同的单元格对齐方式?](https://linux22.com/image/446013/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%90%8C%E4%B8%80%E8%A1%8C%E4%B8%AD%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%90%8C%E7%9A%84%E5%8D%95%E5%85%83%E6%A0%BC%E5%AF%B9%E9%BD%90%E6%96%B9%E5%BC%8F%EF%BC%9F.png)
使用 \makecell,我希望每行的第一列居中(cc),但其余列位于左上角(tl)。这可能吗?
\documentclass{article}
\usepackage{array}
\usepackage{makecell}
\newcolumntype{R}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcommmand\tab{\hspace{10mm}}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{|R{1in}|R{1in}|R{1in}|R{1in}|}
Test Header & Test Header & Test Header & Test Header \\
\hline
\makecell[cc]{Row 1}
& \makecell[tl]{Item 1 \\ \tab Value}
& \makecell[tl]{Item 2 \\ \tab Value \\ Item 3 \\ \tab Value}
& \makecell[tl]{Item 4 \\ \tab Value \\ Item 5 \\ \tab Value \\ Item 6 \\ \tab Value} \\
\hline
\makecell[cc]{Row 2}
& \makecell[tl]{Item 1 \\ \tab Value}
& \makecell[tl]{Item 2 \\ \tab Value \\ Item 3 \\ \tab Value}
& \makecell[tl]{Item 4 \\ \tab Value \\ Item 5 \\ \tab Value \\ Item 6 \\ \tab Value} \\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
tblr
使用包提供的环境非常容易tabularray
。
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}
\centering
\begin{tblr}{
hlines,
%vlines, % uncomment if you really want vertical lines
columns={1in, l, h}, % default left and head alignment
column{1}={c, m}, % column1 horizontal and vertical centered
}
Test Header & Test Header & Test Header & Test Header \\
Row 1
& {Item \\ Value}
& {Item 2 \\ Value \\ Item 3 \\ Value}
& {Item 4 \\ Value \\ Item 5 \\ Value \\ Item 6 \\ Value} \\
Row 2
& {Item 1 \\ Value}
& {Item 2 \\ Value \\ Item 3 \\ Value}
& {Item 4 \\ Value \\ Item 5 \\ Value \\ Item 6 \\ Value} \\
\end{tblr}
\end{table}
\end{document}
在tblr
环境中,您可以像往常一样用 括起条目{}
并用于换行。\\