具有交替行颜色的表格的侧面标签

具有交替行颜色的表格的侧面标签

我在长表中有一个多行列,行的颜色交替变化。交替的颜色溢出到多行中。将第一列涂成白色会消除特殊规则,但似乎不会对行颜色产生影响。我不知道该如何处理这个问题。您有什么建议吗?

这是我的 MWE:

\documentclass[10pt]{article}
\usepackage{longtable, booktabs, rotating, multirow}
\usepackage[table]{xcolor}
\definecolor{tblue}{HTML}{F1F5FA}
\definecolor{tgrey}{HTML}{dddddd}
\renewcommand{\arraystretch}{1.6}
\usepackage{arydshln}
\arrayrulecolor{tgrey}
\begin{document}
\rowcolors{1}{tblue}{white}\centering
\begin{longtable}{>{\columncolor{white}}l !{\color{white}\vrule width 4pt}>{\raggedright}p{3in} p{2.4in}}
\hiderowcolors
&\textbf{Selected representative vars}&\textbf{Correlated vars ($\rho \ge$ 0.8)}\\
\specialrule{0.01em}{0.02em}{0.02em}
\endhead
\specialrule{0.01em}{0.0em}{0em}
\endfoot
\specialrule{0.01em}{0.0em}{0em}
&\multicolumn{2}{l}{\textbf{Subheading}}\\
\specialrule{0.01em}{0.0em}{0em}
\showrowcolors
& Something & Something else
\\
& Something & Something else
\\
& Something & Something else
\\
\hiderowcolors
\specialrule{0.01em}{0.0em}{0em}
&\multicolumn{2}{l}{\textbf{Subheading}}\\
\specialrule{0.01em}{0.0em}{0em}
\showrowcolors
& Something & Something else
\\
& Something & Something else
\\
& Something & Something else
\\
\multirow{-9}{*}{\begin{sideways}\centering \textbf{A long line of sideways text}\end{sideways}}
\end {longtable}
\end{document}

当前表格如下所示: 在此处输入图片描述

答案1

不同的思维方式:使用零宽度框插入垂直文本,而不是给出其自己的列。

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage{longtable, booktabs, graphicx, multirow}
\usepackage[table]{xcolor}
\definecolor{tblue}{HTML}{F1F5FA}
\definecolor{tgrey}{HTML}{dddddd}
\renewcommand{\arraystretch}{1.6}
\usepackage{arydshln}
\arrayrulecolor{tgrey}
\begin{document}
\rowcolors{1}{tblue}{white}\centering
\begin{longtable}{!{\color{white}\vrule width 4pt}>{\raggedright}p{3in} p{2.4in}}
  \hiderowcolors
  \textbf{Selected representative vars}&\textbf{Correlated vars ($\rho \ge$ 0.8)}\\
  \specialrule{0.01em}{0.02em}{0.02em}
  \endhead
  \specialrule{0.01em}{0.0em}{0em}
  \endfoot
  \specialrule{0.01em}{0.0em}{0em}
  \multicolumn{2}{l}{\textbf{Subheading}}\\
  \specialrule{0.01em}{0.0em}{0em}
  \showrowcolors
  Something & Something else \\
  Something & Something else \\
  Something & Something else \\
  \hiderowcolors
  \specialrule{0.01em}{0.0em}{0em}
  \multicolumn{2}{l}{%
    \llap{\smash{\rotatebox[origin=c]{90}{%
      \hspace*{2\normalbaselineskip}% Vertical adjustment
      \textbf{A long line of sideways text}}}%
      \hspace*{\dimexpr\tabcolsep+2em}}% Horizontal adjustment
    \textbf{Subheading}}\\
  \specialrule{0.01em}{0.0em}{0em}
  \showrowcolors
  Something & Something else \\
  Something & Something else \\
  Something & Something else \\
  %\multirow{-9}{*}{\begin{sideways}\centering \textbf{A long line of sideways text}\end{sideways}}
\end{longtable}
\end{document}

\rotatebox[origin=c]{90}{..}横向文本使用以下方式旋转:graphicx(使用时也包括)rotating)。围绕对象中心origin=c旋转。在 ap 上方创建一个eft ,向外推。这有效地将文本从 的左边距放置到。此外,由于我选择的元素并不完全位于表格的中间(垂直),因此将其向上推可与表格主体的其余部分(8 行)正确垂直对齐。c\llapll\tabcolsep+2em2emlongtable2\normalbaselineskip

\smash从对象中删除所有垂直高度 + 深度,从而不影响行高。

答案2

最新版本nicematrix(2021-01-01 的 v 5.8)有专门的工具来解决该问题。

\documentclass[10pt]{article}
\usepackage{nicematrix}
\usepackage{xcolor}
\definecolor{tblue}{HTML}{F1F5FA}
\definecolor{tgrey}{HTML}{dddddd}
\renewcommand{\arraystretch}{1.6}

\begin{document}
\centering
\begin{NiceTabular}{l>{\raggedright\arraybackslash}p{3in}p{2.4in}}%
  [rules/color=tgrey, code-before = {\rowcolors{3-5,7-9}{tblue}{}[restart,cols=2-]} ]
&\textbf{Selected representative vars}&\textbf{Correlated vars ($\rho \ge$ 0.8)}\\
\Hline
\Block{*-1}<\rotate\bfseries>{A long line of sideways text}
&\Block[l]{1-2}{\textbf{Subheading}}\\
& Something & Something else \\
& Something & Something else \\
& Something & Something else \\
\Hline
&\Block[l]{1-2}{\textbf{Subheading}}\\
& Something & Something else \\
& Something & Something else \\
& Something & Something else \\
\Hline
\end{NiceTabular}
\end{document}

您需要多次编译(因为nicematrix使用 PGF/Tikz 节点)。

上述代码的输出

相关内容