表格行的高级背景

表格行的高级背景

我根据不同的品质对表格的行进行颜色编码,并且我认为当需要表示多种品质时,使用条纹背景会很好,而不是为每种组合定义一种新颜色。

我只找到了一种使用图片来表示单个单元格的解决方案,但我希望它表示整行,并且理想情况下,使用类似tcolorboxenigne 和 style 的东西。

编辑:我心里有这样的想法: 在此处输入图片描述

进一步说明:我想像图片中那样为单行着色。行可以占据不同的高度,但列宽是固定的。我认为嵌入 png 作为背景(如果可以以某种方式自动裁剪以适应高度)将是首选解决方案,但话又说回来,我以前没有这方面的经验,tikz也不知道还有其他选择。

从我的项目中剥离出来的 MWE:

\documentclass[11pt]{scrartcl}
%
\makeatletter
\setlength{\@fptop}{0pt}
\makeatother
%
\usepackage[german]{babel} %Worttrennung etc.
\usepackage[utf8]{inputenc} %Umlautkodierung
\usepackage{amsmath, amsfonts, booktabs, mhchem, textgreek, graphicx}
\usepackage{imakeidx}
\usepackage{enumitem}
\usepackage{xifthen, etoolbox}
\usepackage{footnote}
%There is a \begin{savefootnotes} environment which may help in more difficult cases.

\makeindex[title=Namensreaktionen, columns=2]
\makeindex[name=kat, title=Kategorien, columns=2]
\makeindex[name=spec, title=Spezielle Zielstrukturen, columns=2]

\usepackage[top = 3cm, bottom = 3cm, left = 2cm, right = 2cm, a4paper, bindingoffset=0pt]{geometry} 

\usepackage[dvipsnames, table]{xcolor}
\usepackage{longtable}

\usepackage[style=numeric]{biblatex}  
%\addbibresource{Msc.bib}

\definecolor{Gray}{gray}{0.85}
\usepackage[colorlinks=true]{hyperref}

\newcommand{\NameRx}[1]{\textcolor{red}{#1\index{#1}}}
\newcommand{\tabsec}[1]{\multicolumn{4}{c}{#1\index[kat]{#1}}
\\ 
\cmidrule[1pt](lr){1-4}%
} % For formatting categories inside the table

\newcommand{\komment}[1]{\multicolumn{4}{@{\hspace{2em}}p{14cm}@{}}{\small #1} \\ \rule{0pt}{2.5ex}}
\newcommand{\kommentR}[1]{\multicolumn{4}{@{\hspace{2em}}p{14cm}@{}}{\small #1} \\ 
 & & & \\\cmidrule[1pt](lr){1-4}}
 
\newcommand{\don}[1]{\textcolor{green!35!blue!90!black}{d\textsuperscript{#1}}} 
\newcommand{\acc}[1]{\textcolor{red!80!green}{a\textsuperscript{#1}}} 
 
\begin{document}


%\line(1,0){\textwidth}
\centering
\noindent\begin{longtable}{>{\raggedright\let\newline\\\arraybackslash%\hspace{0pt}
}p{0.26\textwidth}p{0.2\textwidth}p{0.25\textwidth}>{\tiny\raggedleft\arraybackslash}p{0.1\textwidth}}\toprule %\arraybackslash is needed here to restore the original definition of \\, which is changed by \raggedright 
Name & Substrat & Reagenz &  \normalsize Verweis\\
\cmidrule[1pt](lr){1-4}
%                                               %
%                                               %
%                                               %
\tabsec{Amidsynthese}
%                                               %
%                                               %
\rowcolor{cyan!15!white} N-Acylierung & \ce{R2NH} & \ce{R^1COX} & - \\
\textalpha -chirale Amid-/Peptidsynthese & \ce{R2NH} &\ce{R^1R^2R^3C-COX},\newline
 X$\neq$Hal & - \\
\kommentR{%
Da unter den Rx. Bed. leicht enolisierbare Carbonsäurederivate ihre \textalpha -Stereoinformation ändern können, wird auf andere Reagenzien zur C.S. Aktivierung zurückgegriffen.
Eine weit verbreitete Methode ist mit DCC (Dicyclohexylcarbodiimid, \ce{(ChN=)2C}), wobei auf die intramolekulare N-Acylierung zu nicht mehr reaktionsfähigem \emph{N}-Acyl-dicyclohexylharnstoff geachtet werden muss.
Hierbei werden weitere Reagenzien (z.B. Pentafluorphenol, \emph{N}-Hydroxybenzotriazol) zur Überführung in ein reaktives gemischtes Anhydrid eingesetzt.
}%   
\end{longtable}
\clearpage

\printindex[kat]
\printindex
%\printindex[spec]
%\printbibliography
\end{document}

答案1

我知道原作者想要一个长(易碎)表格的解决方案,而我没有解决方案。不过,这里有一个解决方案{NiceTabular}nicematrix用于构建不易碎的表格)。

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}

\ExplSyntaxOn
\makeatletter
\NewDocumentCommand \StripRow {m m}
  {
    \peek_remove_spaces:n
      {
        \tl_gput_right:Nx \g_nicematrix_code_before_tl
          { \__pantigny_strip_row:nnn { \arabic { iRow } } { #1 } { #2 } } 
      }
  }
\dim_zero_new:N \l_tmpc_dim
\dim_zero_new:N \l_tmpd_dim
\dim_zero_new:N \l_tmpe_dim
\cs_new_protected:Nn \__pantigny_strip_row:nnn 
  {
    \pgfpicture
    \pgf@relevantforpicturesizefalse
    \pgfpointanchor { nm - \NiceMatrixLastEnv - 1 } { center } 
    \dim_set_eq:NN \l_tmpa_dim \pgf@x
    \pgfpointanchor { nm - \NiceMatrixLastEnv - last } { center } 
    \dim_set_eq:NN \l_tmpc_dim \pgf@x
    \pgfpointanchor { nm - \NiceMatrixLastEnv - #1 } { center } 
    \dim_set_eq:NN \l_tmpd_dim \pgf@y
    \pgfpointanchor { nm - \NiceMatrixLastEnv - \int_eval:n { #1 + 1 } } { center } 
    \dim_set_eq:NN \l_tmpb_dim \pgf@y
    \pgfpathrectanglecorners { \pgfpoint \l_tmpa_dim \l_tmpb_dim } { \pgfpoint \l_tmpc_dim \l_tmpd_dim }
    \pgfsetcolor { #2 }
    \pgfusepath { clip , fill }
    \dim_step_inline:nnnn { \l_tmpa_dim - \l_tmpd_dim + \l_tmpb_dim } { 6 pt } { \l_tmpc_dim }
      {
        \pgfpathmoveto { \pgfpoint { ##1 } \l_tmpb_dim }
        \pgfpathlineto { \pgfpoint { \dim_eval:n { ##1 + 3 pt } } \l_tmpb_dim }
        \pgfpathlineto { \pgfpoint { \dim_eval:n { ##1 + 3 pt + \l_tmpd_dim - \l_tmpb_dim } } \l_tmpd_dim } 
        \pgfpathlineto { \pgfpoint { \dim_eval:n { ##1 + \l_tmpd_dim - \l_tmpb_dim } } \l_tmpd_dim } 
        \pgfpathclose  
      }
    \pgfsetcolor { #3 }
    \pgfusepathqfill
    \endpgfpicture
  }
\makeatother
\ExplSyntaxOff

\begin{document}

\begin{NiceTabular}{@{}cp[l]{5cm}c@{}}
\toprule
Header 1 & Header 2 & Header 3 \\
\midrule
Some text & Some information & A piece on information \\
Some text & Some information & A piece on information \\
\StripRow{red!25}{black!10}
Some text & Some information on several physical lines & A piece on information \\
Some text & Some information & A piece on information \\
\bottomrule
\end{NiceTabular}

\end{document}

您需要多次编译(因为 PGF/Tikz 节点)是创建的remember picture并且(因此)写入 |aux| 文件上。

第一个代码的输出

使用至少 5.19(2021-07-23)的版本nicematrix,可以用 Tikz 图案填充块。

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{NiceTabular}{@{}cp[l]{5cm}c@{}}
\toprule
Header 1 & Header 2 & Header 3 \\
\midrule
Some text & Some information & A piece on information \\
Some text & Some information & A piece on information \\
\Block[tikz={pattern= north east lines, pattern color=red!50}]{1-*}{}
Some text & Some information on several physical lines & A piece on information \\
Some text & Some information & A piece on information \\
\bottomrule
\end{NiceTabular}

\end{document}

第二段代码的输出

相关内容