![旋转表格单元格的大小](https://linux22.com/image/455378/%E6%97%8B%E8%BD%AC%E8%A1%A8%E6%A0%BC%E5%8D%95%E5%85%83%E6%A0%BC%E7%9A%84%E5%A4%A7%E5%B0%8F.png)
我想使用 tabularray 包创建一个自定义表格。我使用了makecell
和rotating
包来旋转一些表格单元格。此外,旋转单元格的长度是用\setlength\rotheadsize{}
命令设置的,正如预期的那样,它会影响所有旋转单元格。但是,我想单独设置大小。
梅威瑟:
\documentclass{article}
\usepackage[paperheight=6in,
paperwidth=5in,
top=10mm,
bottom=20mm,
left=10mm,
right=10mm]{geometry}
\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}
\begin{document}
\begin{table}[ht]
\setlength\rotheadsize{2.0cm}
\renewcommand\theadfont{}
\begin{center}
\begin{talltblr}[
caption = {Example Table},
label = {tbl:example},
]{
width=\linewidth,
colspec={X[1]X[12]|X[1]|X[1]|X[1]|X[1]|},
cell{2}{3-6} = {halign=c,cmd=\rothead},
cell{3-6}{1} = {halign=c,cmd=\rothead},
vline{1}={3-Z}{solid},
vline{2}={3-Z}{solid},
rows = {c},
column{2} = {l},
}
\cline{3-6}
& & \SetCell[c=4]{c} Some Text \\
\cline{3-6}
& & Column 1 & Column 2 & Column 3 & Column 4 \\
\cline{1-6}
\SetCell[r=7]{c} Some longer text & Row 1 & X & X & \\
\cline{2-6}
& Row 2 & X & X & \\
\cline{2-6}
& Row 3 & X & X & \\
\cline{2-6}
& Row 4 & X & X & X \\
\cline{2-6}
& Row 5 & X & & X \\
\cline{2-6}
& Row 6 & X & & X \\
\cline{2-6}
& Row 7 & X & & X \\
\hline
\end{talltblr}
\end{center}
\end{table}
\end{document}
当为第二行中的旋转单元格设置大小时,第一列中的文本将变成多行。另一方面,当根据第一列设置大小时,第二列的高度会变得太高。
答案1
使用您有趣的答案作为起点,您的问题的可能(更一致)解决方案可能是:
\documentclass{article}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}
\begin{document}
\begin{table}[ht]
\caption{Example Table}
\label{tbl:example}
\renewcommand\theadfont{}
\centering
\begin{tblr}{hline{1,2} = {3-Z}{solid}, vline{1,2} = {3-Z}{solid},
hline{3-Z} = {solid}, vline{3-Z}={solid},
colspec = {c X[l] *{4}{c} },
row{2} = {cmd=\settowidth\rotheadsize{column 3 }\rothead}, % <---
column{1} = {cmd=\settowidth\rotheadsize{Some longer text }\rothead}, % <---
}
& & \SetCell[c=4]{c} Some Text
& & & \\
& & Column 1
& Column 2
& Column 3
& Column 4 \\
\SetCell[r=7]{c} Some longer text
& Row 1 & X & & & \\
& Row 2 & & X & & \\
& Row 3 & & & X & \\
& Row 4 & & & & X \\
& Row 5 & & & X & \\
& Row 6 & & X & & \\
& Row 7 & X & & & \\
\end{tblr}
\end{table}
\end{document}
这使
从上图中可以看出,在表格主体的 MWE 中,保留了写入单元格内容的通常方式,而旋转命令与表格前言中的旋转单元格大小设置合并。
答案2
也许有更好的解决方案。目前,我只想\rotatebox[origin=c]{90}{...}
在受影响的单元格中使用
\documentclass{article}
\usepackage[paperheight=6in,
paperwidth=5in,
top=10mm,
bottom=20mm,
left=10mm,
right=10mm]{geometry}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}
\begin{document}
\begin{table}[ht]
\settowidth{\rotheadsize}{Column 4}
\renewcommand\theadfont{}
\begin{center}
\begin{talltblr}[
caption = {Example Table},
label = {tbl:example},
]{
width = 0.8\linewidth,
colspec = {X X[12] *4{X}},
cell{2}{3-6} = {halign=c,cmd=\rothead},
vline{1} = {3-Z}{solid},
vline{2} = {3-Z}{solid},
vline{3-Z} = {},
hline{1,2} = {3-6}{},
hline{3-Z} = {},
rows = {c},
column{2} = {l},
}
& & \SetCell[c=4]{c} Some Text \\
& & Column 1 & Column 2 & Column 3 & Column 4 \\
\SetCell[r=7]{} \rotatebox[origin=c]{90}{Some longer text}
& Row 1 & X & X & & \\
& Row 2 & & X & X & \\
& Row 3 & & X & X & \\
& Row 4 & & X & X & X \\
& Row 5 & & X & & X \\
& Row 6 & & X & & X \\
& Row 7 & & X & & X \\
\end{talltblr}
\end{center}
\end{table}
\end{document}
答案3
\rothead
我没有使用命令作为的参数,而是cell
使用它并将\setlength
和\settowidth
命令作为cell
参数。
\documentclass{article}
% Using the geometry package with a small
% page size to create the article graphic
\usepackage[paperheight=6in,
paperwidth=5in,
top=10mm,
bottom=20mm,
left=10mm,
right=10mm]{geometry}
\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}
\begin{document}
\begin{table}[ht]
% \setlength\rotheadsize{2.0cm}
\renewcommand\theadfont{}
\begin{center}
\begin{talltblr}[
caption = {Example Table},
label = {tbl:example},
]{
width=\linewidth,
colspec={X[1]X[12]|X[1]|X[1]|X[1]|X[1]|},
cell{2}{3-6} = {halign=c,cmd=\setlength\rotheadsize{1.5cm}},
cell{3-6}{1} = {halign=c,cmd=\settowidth\rotheadsize{\theadfont Some longer text}},
vline{1}={3-Z}{solid},
vline{2}={3-Z}{solid},
rows = {c},
column{2} = {l},
}
\cline{3-6}
& & \SetCell[c=4]{c} Some Text \\
\cline{3-6}
& & \rothead{Column 1} & \rothead{Column 2} & \rothead{Column 3} & \rothead{Column 4} \\
\cline{1-6}
\SetCell[r=7]{c} \rothead{Some longer text} & Row 1 & X & X & \\
\cline{2-6}
& Row 2 & X & X & \\
\cline{2-6}
& Row 3 & X & X & \\
\cline{2-6}
& Row 4 & X & X & X \\
\cline{2-6}
& Row 5 & X & & X \\
\cline{2-6}
& Row 6 & X & & X \\
\cline{2-6}
& Row 7 & X & & X \\
\hline
\end{talltblr}
\end{center}
\end{table}
\end{document}