在第一个表中,我为特定列和行制作了热图。我想将其调整为第二个表(标签表 1),使其适用于行项 Nr.1 和 Nr.2 以及列 1 至 5(无背景色),最后一列 N 也没有背景色。实现此目的的最佳方法是什么?
\documentclass[doc,natbib,floatsintext,12pt,noextraspace]{apa6}
\usepackage[all]{nowidow}
\usepackage[document]{ragged2e}
\usepackage[english]{babel}
\usepackage[obeyspaces]{url}
\usepackage[T1]{fontenc}
\usepackage[tracking=true]{microtype}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,siunitx,caption}
\usepackage{array}
\usepackage{enumitem}
\usepackage{flafter}
\usepackage{float}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{pdflscape}
\usepackage{scrextend}
\usepackage{setspace}
\usepackage{tabu}
\usepackage{tabularx}
\usepackage{textcomp}
\usepackage{threeparttable}
\usepackage{tocloft}
\usepackage[table]{xcolor}
\usepackage{collcell}
\usepackage{hhline}
\usepackage{pgf}
\doublespacing{}
\raggedbottom{}
\renewcommand{\theadfont}{\normalfont}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage{fbb}
\usepackage[libertine]{newtxmath}
\def\colorModel{hsb} %You can use rgb or hsb
\newcommand\ColCell[1]{
\pgfmathparse{#1<70?1:0} %Threshold for changing the font color into the cells
\ifnum\pgfmathresult=0\relax\color{black}\fi
\pgfmathsetmacro\compA{0.45-#1/270} %Component R or H
\pgfmathsetmacro\compB{#1/100} %Component G or S
\pgfmathsetmacro\compC{0.3+1} %Component B or B
\edef\x{\noexpand\centering\noexpand\cellcolor[\colorModel]{\compA,\compB,\compC}}\x #1}
\newcolumntype{E}{>{\collectcell\ColCell}m{0.4cm}<{\endcollectcell}} %Cell width
\begin{document}
\newcommand\items{3} %Number of classes
\arrayrulecolor{white} %Table line colors
\noindent\begin{tabular}{c*{\items}{|E}|r}
\multicolumn{1}{c}{} &
\multicolumn{1}{c}{A} &
\multicolumn{1}{c}{B} &
\multicolumn{1}{c}{C} &
\multicolumn{1}{c}{N} \\ \hhline{~*\items{|-}|}
Row 1 & 90 & 0 & 10 & 12 \\
Row 2 & 10 & 80 & 10 & 10 \\
Row 3 & 30 & 0 & 70 & 19 \\
Row 4 & 30 & 50 & 70 & 19 \\
Row 5 & 30 & 0 & 70 & 19 \\
\end{tabular}
{\footnotesize
\begin{spacing}{1.2}
\setlength\tabcolsep{2pt}
\begin{longtable}{
@{}
>{\raggedright}p{8.3cm}
>{\centering}p{1.1cm}
>{\centering}p{1.1cm}
>{\centering}p{1.1cm}
>{\centering}p{1.1cm}
>{\centering}p{1.1cm}
p{0.5cm}
@{}}
% header ------------------------
\caption{Something Something Amazing} \\
\midrule
\multicolumn{0}{l}{\hspace{-2pt}Variable}&
\multicolumn{0}{c}{{\footnotesize Variants}}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{1}{c}{}\\
\midrule
% \noindent\rule{7.3cm}{0.4pt}\\
\textbf{Something Text} & 1 & 2 & 3 & 4 & 5 & N \\
\midrule\addlinespace[2ex]
Nr.1 Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit. & 14 & 31 & 25 & 20 & 9 & 64 \\
Nr. 2 Integer aliquet volutpat odio at vulputate. Morbi laoreet, ex eget viverra posuere. & 8 & 30 & 44 & 14 & 5 & 64 \\
\midrule
\end{longtable}
\end{spacing}
}
\end{document}
答案1
以下内容可能适合您的需求。我添加了自定义E
类型列的修改版本。E
类型列派生自m
类型 nd,并且自动为0.4cm
宽。虽然这适合第一个表,但在第二个表中,您最初使用了不同的列说明符。因此,我添加了F
接受参数的类型列,如下所示:
定义: \newcolumntype{F}[1]{>{\collectcell\ColCell}#1<{\endcollectcell}}
用法:F{p{3cm}}
或F{c}
或 F{>{\centering\arraybackslash}p{1.1cm}}
为了在您的第二个表中使用上面描述的新列类型,我已将五次出现的 替换>{\centering}p{1.1cm}
为*{5}{F{>{\centering\arraybackslash}p{1.1cm}}}
。
最后,我还添加了一个占位符\shorttitle
以使代码可编译。如果没有,\shorttitle
您将收到一条错误消息,抱怨缺少该命令。
\documentclass[doc,natbib,floatsintext,12pt,noextraspace]{apa6}
\usepackage[all]{nowidow}
\usepackage[document]{ragged2e}
\usepackage[english]{babel}
\usepackage[obeyspaces]{url}
\usepackage[T1]{fontenc}
\usepackage[tracking=true]{microtype}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,siunitx,caption}
\usepackage{array}
\usepackage{enumitem}
\usepackage{flafter}
\usepackage{float}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{pdflscape}
\usepackage{scrextend}
\usepackage{setspace}
\usepackage{tabu}
\usepackage{tabularx}
\usepackage{textcomp}
\usepackage{threeparttable}
\usepackage{tocloft}
\usepackage[table]{xcolor}
\usepackage{collcell}
\usepackage{hhline}
\usepackage{pgf}
\doublespacing{}
\raggedbottom{}
\renewcommand{\theadfont}{\normalfont}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage{fbb}
\usepackage[libertine]{newtxmath}
\shorttitle{short title}
\def\colorModel{hsb} %You can use rgb or hsb
\newcommand\ColCell[1]{
\pgfmathparse{#1<70?1:0} %Threshold for changing the font color into the cells
\ifnum\pgfmathresult=0\relax\color{black}\fi
\pgfmathsetmacro\compA{0.45-#1/270} %Component R or H
\pgfmathsetmacro\compB{#1/100} %Component G or S
\pgfmathsetmacro\compC{0.3+1} %Component B or B
\edef\x{\noexpand\centering\noexpand\cellcolor[\colorModel]{\compA,\compB,\compC}}\x #1}
\newcolumntype{E}{>{\collectcell\ColCell}m{0.4cm}<{\endcollectcell}} %Cell width
\newcolumntype{F}[1]{>{\collectcell\ColCell}#1<{\endcollectcell}} %Cell width
\begin{document}
\newcommand\items{3} %Number of classes
\arrayrulecolor{white} %Table line colors
\noindent\begin{tabular}{c*{\items}{|E}|r}
\multicolumn{1}{c}{} &
\multicolumn{1}{c}{A} &
\multicolumn{1}{c}{B} &
\multicolumn{1}{c}{C} &
\multicolumn{1}{c}{N} \\ \hhline{~*\items{|-}|}
Row 1 & 90 & 0 & 10 & 12 \\
Row 2 & 10 & 80 & 10 & 10 \\
Row 3 & 30 & 0 & 70 & 19 \\
Row 4 & 30 & 50 & 70 & 19 \\
Row 5 & 30 & 0 & 70 & 19 \\
\end{tabular}
{\footnotesize
\begin{spacing}{1.2}
\setlength\tabcolsep{2pt}
\begin{longtable}{
@{}
>{\raggedright}p{8.3cm}
*{5}{F{>{\centering\arraybackslash}p{1.1cm}}}
p{0.5cm}
@{}}
% header ------------------------
\caption{Something Something Amazing} \\
\midrule
\multicolumn{0}{l}{\hspace{-2pt}Variable}&
\multicolumn{0}{c}{{\footnotesize Variants}}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{0}{c}{{\footnotesize }}&
\multicolumn{1}{c}{}\\
\midrule
% \noindent\rule{7.3cm}{0.4pt}\\
\textbf{Something Text} & 1 & 2 & 3 & 4 & 5 & N \\
\midrule\addlinespace[2ex]
Nr.1 Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit. & 14 & 31 & 25 & 20 & 9 & 64 \\
Nr. 2 Integer aliquet volutpat odio at vulputate. Morbi laoreet, ex eget viverra posuere. & 8 & 30 & 44 & 14 & 5 & 64 \\
Nr.1 Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit. & 14 & 31 & 25 & 20 & 9 & 64 \\
Nr. 2 Integer aliquet volutpat odio at vulputate. Morbi laoreet, ex eget viverra posuere. & 8 & 30 & 44 & 14 & 5 & 64 \\
\midrule
\end{longtable}
\end{spacing}
}
\end{document}