我尝试创建一个宽度与 对应的表格1.2\linewidth
,并在第 4 至第 9 列中对单元格进行着色并旋转文本。我无法对包含旋转文本的单元格进行着色并将表格拉伸到1.2\linewidth
页面上。您能帮助我吗?
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage{booktabs}
\definecolor{mydarkblue}{RGB}{14,101,123}
\definecolor{mybrightblue}{RGB}{0,176,240}
\definecolor{mybrightgreen}{RGB}{197,224,180}
\definecolor{mybrightorange}{RGB}{248,203,173}
\definecolor{mybrightred}{RGB}{255,109,109}
\begin{document}
\newcommand{\STAB}[1]{\begin{tabular}{@{}c@{}}\cellcolor{mybrightblue}#1
\begin{table}[!h]
\centering
\scriptsize
\begin{tabular*}{1.2\linewidth}{|l|l|l|c|c|c|c|c|c|l|l|@{}}
\hline
\multicolumn{1}{|c|}{\cellcolor{mydarkblue}\textbf{ID}} &
\multicolumn{1}{l|}{\cellcolor{mydarkblue}\textbf{Test}} &
\multicolumn{1}{l|}{\cellcolor{mydarkblue}\textbf{Test Text}} &
\multicolumn{6}{c|}{\cellcolor{mydarkblue}\textbf{Inspection Criteria}} &
\multicolumn{1}{l|}{\cellcolor{mydarkblue}\textbf{New}} & \multicolumn{1}{c|}{\cellcolor{mydarkblue}\textbf{Comment}} \\ \cline{4-9}
\cellcolor{mydarkblue} & \multicolumn{1}{l|}{\cellcolor{mydarkblue}\textbf{Text}} & \multicolumn{1}{l|}{\cellcolor{mydarkblue}\textbf{Description}} & \multirow{3}{*}{\cellcolor{mybrightblue}\STAB{\rotatebox[origin=c]{90}{~~Criteria 1~~}}} &
\multirow{3}{*}{\cellcolor{mybrightblue}\STAB{\rotatebox[origin=c]{90}{Criteria 2}}} &
\multirow{3}{*}{\cellcolor{mybrightblue}\STAB{\rotatebox[origin=c]{90}{Criteria 3}}} &
\multirow{3}{*}{\cellcolor{mybrightblue}\STAB{\rotatebox[origin=c]{90}{Criteria 4}}} &
\multirow{3}{*}{\cellcolor{mybrightblue}\STAB{\rotatebox[origin=c]{90}{Criteria 5}}} &
\multirow[c]{3}{*}{\cellcolor{mybrightblue}\STAB{\rotatebox[origin=c]{90}{Criteria 6}}} &
\multicolumn{1}{l|}{\cellcolor{mydarkblue}\textbf{Workflow}} & \cellcolor{mydarkblue} \\
\cellcolor{mydarkblue} & \multirow[t]{2}{*}{\cellcolor{mydarkblue}\textbf{Name}} & \cellcolor{mydarkblue} & & & & & & & \cellcolor{mydarkblue}\textbf{State} & \cellcolor{mydarkblue} \\
\cellcolor{mydarkblue} & \cellcolor{mydarkblue} & \cellcolor{mydarkblue} & & & & & & & \cellcolor{mydarkblue} & \cellcolor{mydarkblue} \\ \hline
T-123 & Test Text 1 & Description 1 & \cellcolor{mybrightgreen} \cellcolor{mybrightgreen} OK & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightgreen} APPROVED & \\ \hline
T-124 & Test Text 2 & Description 2 & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightred} NOK & \cellcolor{mybrightorange} PARTLY & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightgreen} OK & \cellcolor{mybrightred} NOK & \cellcolor{mybrightred} REJECTED & \\ \hline
& & & & & & & & & & \\ \hline
& & & & & & & & & & \\ \hline
\end{tabular*}
\end{table}
\end{document}
包含条件的单元格应完全填充,包含单词 OK、PARTLY、NOK、APPROVED、REJECTED 的单元格应像条件单元格一样旋转。此外,表格的宽度应为1.2\linewidth
。条件的列应等宽。如果可能,第 1、2、3 和 11 列应为多行。
答案1
为了完整起见,下面是calstable
使用包的卡路里:
\documentclass{article}
\usepackage{graphicx, cals, xcolor}
\usepackage{changepage}
\let\nc=\nullcell % Shortcuts
\let\sc=\spancontent
\definecolor{mydarkblue}{RGB}{14,101,123}
\definecolor{mybrightblue}{RGB}{0,176,240}
\definecolor{mybrightgreen}{RGB}{197,224,180}
\definecolor{mybrightorange}{RGB}{248,203,173}
\definecolor{mybrightred}{RGB}{255,109,109}
\begin{document}
\noindent Blindtext. The quick brown fox jumped over the lazy dog. Which is just a text to see the text line.
\begin{calstable}[c]
% Defining 11 column relativ to each other and relativ to the margins
\colwidths{{\dimexpr(1.2\columnwidth/20)*2\relax}
{\dimexpr(1.2\columnwidth/20)*3\relax}
{\dimexpr(1.2\columnwidth/20)*3\relax}
{\dimexpr(1.2\columnwidth/20)*1\relax}
{\dimexpr(1.2\columnwidth/20)*1\relax}
{\dimexpr(1.2\columnwidth/20)*1\relax}
{\dimexpr(1.2\columnwidth/20)*1\relax}
{\dimexpr(1.2\columnwidth/20)*1\relax}
{\dimexpr(1.2\columnwidth/20)*1\relax}
{\dimexpr(1.2\columnwidth/20)*3\relax}
{\dimexpr(1.2\columnwidth/20)*3\relax}
}
% The tabular fills 120% of the text area
% Set up the tabular
\makeatletter
\def\cals@framers@width{0.4pt} % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.4pt}
\def\cals@bodyrs@width{0.4pt}
\cals@setpadding{Ag}
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0.4pt} % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.4pt}
\def\cals@bgcolor{} % Define cals@bgcolor to empty
\def\dblue{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{mydarkblue}
\else \def\cals@bgcolor{} \fi}
\def\bblue{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{mybrightblue}
\else \def\cals@bgcolor{} \fi}
\def\bgreen{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{mybrightgreen}
\else \def\cals@bgcolor{} \fi}
\def\bred{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{mybrightred}
\else \def\cals@bgcolor{} \fi}
\def\borange{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{mybrightorange}
\else \def\cals@bgcolor{} \fi}
\makeatother
\thead{\small\bfseries
\brow
\dblue\alignL\nc{tlr}
\alignL\nc{tlr}
\alignL\nc{tlr}
\alignC\nc{ltb}
\alignC\nc{tb}
\alignC\nc{tb}
\alignC\nc{tb}
\alignC\nc{tb}
\alignC\nc{rtb}\sc{Inspection Criteria}
\alignL\nc{tlr}
\alignL\nc{tlr}
\erow
\brow
\alignL\nc{blr}\sc{ID}
\alignL\nc{blr}\sc{Test\par Text\par Name}
\alignL\nc{blr}\sc{Test Text\par Description}\dblue
\bblue\alignC\cell{\rotatebox[origin=c]{90}{Criteria 1}}
\alignC\cell{\rotatebox[origin=c]{90}{Criteria 2}}
\alignC\cell{\rotatebox[origin=c]{90}{Criteria 3}}
\alignC\cell{\rotatebox[origin=c]{90}{Criteria 4}}
\alignC\cell{\rotatebox[origin=c]{90}{Criteria 5}}
\alignC\cell{\rotatebox[origin=c]{90}{Criteria 6}}\bblue
\dblue\alignL\nc{blr}\sc{New\par Workflow\par State}
\alignL\nc{blr}\sc{Comment}\bblue
\erow
\mdseries}
\brow
\alignL\cell{T-123}
\alignL\cell{Test Text 1}
\alignL\cell{Description 1}
\bgreen\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}
\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}
\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}
\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}
\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}
\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}
\alignL\cell{\vfil\rotatebox[origin=c]{90}{APPROVED}}\bgreen
\alignL\cell{}
\erow
\brow
\alignL\cell{T-124}
\alignL\cell{Test Text 2}
\alignL\cell{Description 2}
\bgreen\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}\bgreen
\bred\alignC\cell{\vfil\rotatebox[origin=c]{90}{NOK}}\bred
\borange\alignC\cell{\vfil\rotatebox[origin=c]{90}{PARTLY}}\borange
\bgreen\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}
\alignC\cell{\vfil\rotatebox[origin=c]{90}{OK}}\bgreen
\bred\alignC\cell{\vfil\rotatebox[origin=c]{90}{NOK}}
\alignL\cell{\vfil\rotatebox[origin=c]{90}{REJECTED}}\bred
\alignL\cell{}
\erow
\brow
\alignL\cell{T-125}
\alignL\cell{}
\alignL\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignL\cell{}
\alignL\cell{}
\erow
\brow
\alignL\cell{T126}
\alignL\cell{}
\alignL\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignC\cell{}
\alignL\cell{}
\alignL\cell{}
\erow
\end{calstable}
\end{document}
答案2
这是一个可能的解决方案。比您的 MWE 代码简单得多。特别是,要求表格必须比线宽宽,这很有挑战性。当然,在表格中组合线条和颜色时,您会遇到常见问题。线条被颜色覆盖。
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{ adjustbox}
\usepackage{array}
\usepackage{changepage}
\definecolor{mydarkblue}{RGB}{14,101,123}
\definecolor{mybrightblue}{RGB}{0,176,240}
\definecolor{mybrightgreen}{RGB}{197,224,180}
\definecolor{mybrightorange}{RGB}{248,203,173}
\definecolor{mybrightred}{RGB}{255,109,109}
\newcolumntype{F}{>{\raggedright\arraybackslash}p{\dimexpr(0.095\linewidth-(2\tabcolsep+\arrayrulewidth))}}
\newcolumntype{P}{>{\raggedright\arraybackslash}p{\dimexpr(0.15\linewidth-(2\tabcolsep+\arrayrulewidth))}}
\newcolumntype{Q}{>{\centering\arraybackslash}p{\dimexpr(0.05\linewidth-(2\tabcolsep+\arrayrulewidth))}}
\begin{document}
\noindent Blindtext. The quick brown fox jumped over the lazy dog. Which is just a text to see the text line.
\begin{adjustwidth}{-0.1\linewidth}{-0.1\linewidth}
\noindent Blindtext. The quick brown fox jumped over the lazy dog. Which is just a text to see the text line.
\setlength{\extrarowheight}{3pt}
\def\arraystretch{1.2}
\centering
\scriptsize
\begin{tabular}{|F|P|P|Q|Q|Q|Q|Q|Q|P|P|}
\hline
\rowcolor{mydarkblue}
\bfseries ID &
\bfseries Test &
\bfseries Test Text &
\multicolumn{6}{c|}{\bfseries Inspection Criteria} &
\bfseries New &
\bfseries Comment
\\\cline{4-9}
\rowcolor{mybrightblue}
\cellcolor{mydarkblue}&
\cellcolor{mydarkblue}\begin{tabular}[b]{@{}l@{}}\cellcolor{mydarkblue}\bfseries Text\\ \cellcolor{mydarkblue}Name\end{tabular}
&
\cellcolor{mydarkblue}\cellcolor{mydarkblue}\begin{tabular}[b]{@{}l@{}}\cellcolor{mydarkblue}\bfseries Description\\\cellcolor{mydarkblue}~\end{tabular}&
\rotatebox[origin=c]{90}{~Criteria 1} &
\rotatebox[origin=c]{90}{~Criteria 2} &
\rotatebox[origin=c]{90}{~Criteria 3} &
\rotatebox[origin=c]{90}{~Criteria 4} &
\rotatebox[origin=c]{90}{~Criteria 5} &
\rotatebox[origin=c]{90}{~Criteria 6} &
\cellcolor{mydarkblue}\begin{tabular}[b]{@{}l@{}}\cellcolor{mydarkblue}\bfseries Workflow\\ \cellcolor{mydarkblue}State \end{tabular}&
\cellcolor{mydarkblue}
\\\hline
T-123 &
Test Text 1 &
Description 1 &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{~APPROVED~} &
\\ \hline
T-124 &
Test Text 2 &
Description 2 &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK}&
\cellcolor{mybrightred}\rotatebox[origin=c]{90}{NOK}&
\cellcolor{mybrightorange}\rotatebox[origin=c]{90}{PARTLY} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightgreen}\rotatebox[origin=c]{90}{OK} &
\cellcolor{mybrightred}\rotatebox[origin=c]{90}{NOK} &
\cellcolor{mybrightred}\rotatebox[origin=c]{90}{~REJECTED~} &
\\ \hline
& & & & & & & & & & \\ \hline
& & & & & & & & & & \\ \hline
\end{tabular}
\end{adjustwidth}
\end{document}