宽度边框问题 tabularray 环境

宽度边框问题 tabularray 环境

上次我得到了很大的帮助,现在我刚接触乳胶,已经尝试了一段时间才弄清楚……我希望你能帮助我解决问题。我尝试以这样的风格设计一个表格(白线是一种错误的可视化): 在此处输入图片描述

我最大的问题是表格宽度超出了文本框,我不知道该怎么办。也许 tabularry 不是完美的环境?我已经尝试将其作为 tblr 放在表格环境中,但这也无济于事。否则,我仍然必须弄清楚如何“删除”最后 5 列中的 h 和 v 线,因为它应该是没有每种颜色线条的区域。(我会尝试使用 vlines = {1, 2, 3, 4}{solid} 和 hlines{1, 2, 3} = {1}{-}{} - 但说实话,这似乎相当复杂,最终也许有更好的方法?)最后,我仍然必须将标题 (1+2) 后每行的行高设置为相同的高度。我很确定我会解决这个问题,但欢迎任何帮助/提示 :)

\documentclass{article}
\usepackage{tabularray}
\NewDocumentCommand \TblrAlignCenter { } { \centering }
\usepackage{float}

\begin{document}

\begin{longtblr}[
    caption = {cap},
    lable = {lab},
    presep = {6pt}
    ]{
    hlines, vlines,
    colspec = {X[2.4,c,m] X[1.2,c,m] X[1.2,c,m]  X[0.4,l,m] X[0.4,l,m] X[0.4,l,m] X[0.4,c,m] X[0.4,c,m]}, width=\linewidth, %columnes are not linewidth
    row{1}  = {font=\bfseries, bg=black, fg=white},
    row{2}  = {font=\bfseries, bg=black, fg=white},
    rowhead = {1} %should actually be 1 and 2 - How can I achieve it?
    }  
\SetCell[r=2]{c}{Multirow Head} & \SetCell[c=2]{c}{Multicol Head 1 with multiple lines} & & \SetCell[c=2]{c}{Multicol Head 2 with multiple lines} & & & & \\
& R1 & R2 & TX 1 & TX 2 & TX 3 & TX 4 & TX 5 \\
Category name with same height for each row & numbers & numbers & \SetCell[r=3]{c,m,bg=gray9}{TL 1} & \SetCell[r=7]{c,m,bg=gray8}{TL 2} & \SetCell[r=9]{c,m,bg=gray7}{TL 3} & \SetCell[r=10]{c,m,bg=gray6}{TL 4} & \SetCell[r=10]{c,m,bg=gray5}{TL 5} \\
cat name & numbers & numbers & & & & & \\
cat name & numbers & numbers & & & & & \\
cat name & numbers & numbers & \SetCell[r=4]{c,m,bg=gray8}{} & & & & \\ 
cat name & numbers & numbers & & & & & \\
cat name & numbers & numbers & & & & & \\
cat name & numbers & numbers & & & & & \\
cat name & numbers & numbers & \SetCell[r=2]{c,m,bg=gray7}{} & \SetCell[r=2]{c,m, bg=gray7}{} & & & \\ 
cat name & numbers & numbers & & & & & \\
cat name & numbers & numbers & \SetCell[c=3]{c,m,bg=gray6}{} & & & & \\ 
\end{longtblr}

\end{document}

当前的屏幕截图(红线 = 文本宽度):

在此处输入图片描述

我实施的软件包和设置:

\raggedbottom
\usepackage[utf8]{inputenc} 
\usepackage{mathptmx}
\usepackage{textcomp}
\usepackage[english]{babel}
\usepackage[UKenglish]{isodate}
\usepackage[hidelinks]{hyperref} 
\usepackage{csquotes}
\usepackage{natbib}
\renewcommand{\bibsection}{}
\bibliographystyle{apalike}
\usepackage{url}
\usepackage[skip=6pt]{parskip} 
\usepackage{fancyhdr} 
\usepackage{graphicx} 
\usepackage{xcolor}
\usepackage{pdfpages} 
\usepackage{tocloft} 
\usepackage{titletoc} 
\usepackage[toc,page]{appendix} 
\usepackage[printonlyused]{acronym} 
\usepackage{enumitem} 
\usepackage[acronym]{glossaries}
\glsdisablehyper 
\usepackage{setspace} 
\singlespacing
\usepackage{lscape} 
\usepackage{vmargin} 
\usepackage[tableposition=top, font=small, labelfont=bf, belowskip=6pt, aboveskip=6pt,  justification=centering]{caption} 
\captionsetup[figure]{belowskip=0pt}
\setlength{\intextsep}{6pt}
\usepackage{float} 
\usepackage{rotating} 
\usepackage{harveyballs} 
\usepackage{epsfig} 
\usepackage{booktabs} 
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usepackage{multirow}
\usepackage{tabularray} 
\NewDocumentCommand \TblrAlignCenter { } { \centering } 
\ExplSyntaxOn
\prg_generate_conditional_variant:Nnn \tl_if_empty:n { e } { TF }
\let \IfTokenListEmpty = \tl_if_empty:eTF
\ExplSyntaxOff
\DefTblrTemplate{firsthead}{default}{%
  \addtocounter{table}{-1}%
  \IfTokenListEmpty{\InsertTblrText{entry}}{%
    \captionof{table}{\InsertTblrText{caption}}%
  }{%
    \captionof{table}[\InsertTblrText{entry}]{\InsertTblrText{caption}}%
  }%
}
\DefTblrTemplate{middlehead,lasthead}{default}{%
  \addtocounter{table}{-1}%
  \captionof{table}[]{\InsertTblrText{caption}(Continued)}%
}
\SetTblrTemplate{caption-lot}{empty}
\setmarginsrb{3 cm}{1.5 cm}{2 cm}{1.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm} 

答案1

我认为白线是预期行为。一旦您开始像这样组织表格,您就会构建许多小区域/间隙(粗线),无论是否是错误,您都必须手动处理它们。

消除白线的一种方法是使用与背景相同的颜色绘制规则。但是,下面我将单元格与一个额外的列合并。

您可以通过指定参数来控制行高ht。您还可以通过指定上下间隙来更改间距。

我不知道你希望长表如何分页。值得注意的是,\\*使用标准可能会有所帮助,而不是使用标准\\来指示哪些行应该一起“移动”到下一页而不分页

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{geometry}
% \NewDocumentCommand \TblrAlignCenter { } { \centering }


\begin{document}
  \begin{longtblr}[
    caption = {cap},
    label = {lab},
    presep = {6pt}
    ]{
    width=\linewidth,
      width=\columnwidth,
      colspec = {
        X[2.4,1,m, cmd=\raggedright]
        *2{X[1.2,c,m]}
        *5{X[0.4,c,m]}
      },
      % Rules and bars
      hline{1,3,Z} = {1.2pt},
      hline{4-5,7-9,11} = {1-3}{dash=dotted},
      hline{6} = {1-4}{1.2pt}, 
      hline{10} = {1-5}{1.2pt},
      hline{12} = {1-6}{1.2pt},
      vlines, vline{1,Z} = {1.2pt},
      vline{5} = {1-5}{1.2pt},  
      vline{6} = {1-9}{1.2pt},
      vline{7} = {1-11}{1.2pt},
      vline{8} = {1-Z}{1.2pt},
      % Header
      row{1,2}  = {font=\bfseries, ht = 4ex, bg=black, fg=white},   % 
      rowhead = {2},
      %
      cells = {font=\small},
      cell{6}{4} = {r=4,c=2}{gray8},
      cell{10}{4} = {r=2,c=3}{gray7},
      cell{12}{4} = {c=4}{gray6},
    }  
    \SetCell[r=2]{c} Multirow Head
    & \SetCell[c=2]{} {Multicol Head 1 with\\multiple lines} &
    & \SetCell[c=5]{} {Multicol Head 2 with\\multiple lines} & & & & \\
    & R1 & R2 & TX 1 & TX 2 & TX 3 & TX 4 & TX 5 \\
    Category name with same height for each row & numbers & numbers
    & \SetCell[r=3]{gray9} TL 1
    & \SetCell[r=7]{gray8} TL 2
    & \SetCell[r=9]{gray7} TL 3
    & \SetCell[r=10]{gray6} TL 4
    & \SetCell[r=10]{gray5} TL 5 \\
    cat name & numbers & numbers & & & & & \\
    cat name & numbers & numbers & & & & & \\
    cat name & numbers & numbers & & & & & \\ 
    cat name & numbers & numbers & & & & & \\
    cat name & numbers & numbers & & & & & \\
    cat name & numbers & numbers & & & & & \\
    cat name & numbers & numbers & & & & & \\ 
    cat name & numbers & numbers & & & & & \\
    cat name & numbers & numbers & & & & & \\ 
  \end{longtblr}
\end{document}

在此处输入图片描述

相关内容