旋转表格单元格的大小

旋转表格单元格的大小

我想使用 tabularray 包创建一个自定义表格。我使用了makecellrotating包来旋转一些表格单元格。此外,旋转单元格的长度是用\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}

解决方案结果

相关内容