我对 LaTeX 还不太熟悉,我想创建一个比较表,其中表格的第一行和第一列都是垂直书写的。我尝试了在 stackexchange 上找到的几种解决方案,包括“多列”和“旋转”,但都没有成功(例如文本不显示或水平书写)。
我成功通过此处找到的线程创建了具有预期颜色的表格。
我希望的结果如下:
我目前得到的结果:
代码 :
\documentclass[11pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tabu}
\usepackage{colortbl}
\usepackage{array,multirow,graphicx}
\begin{document}
\taburowcolors[2]{white .. black!20}
\tabulinesep=4pt
\begin{tabu}{|>{\cellcolor{black!60}\color{white}}r|X[cm]|X[cm]|}
\hline
\rowcolor{black!80}\cellcolor{black!80}Java & \color{white}Open source& \color{white}\# operators \\
Tool1 & Yes & 1\\
Tool2 & Yes & 2\\
Tool3 & Yes & 3\\
\rowcolor{black!80}\cellcolor{black!80}C/C++ & ~ & ~ \\
Tool1 & Yes & 1\\
Tool2 & No & 2\\
Tool3 & Yes & 3\\
\rowcolor{black!80}\cellcolor{black!80}Python& ~ & ~ \\
Tool1 & No & 1\\
Tool2 & Yes & 2\\
Tool3 & Yes & 3\\
\hline
\end{tabu}
\end{document}
答案1
像这样?
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\usepackage{multirow, tabu}
\begin{document}
\taburowcolors[2]{white .. black!20}
\tabulinesep=4pt
\begin{tabu}{>{\columncolor{black!80}\color{white}}c r |
c | c
!{\vrule width 0.5pt}@{}
!{\color{black!80}\vrule width 1ex}
}
\rowcolor{black!80}
& \multicolumn{1}{c!{\color{white}\vline}}{}
& \multicolumn{1}{c!{\color{white}\vline}}{%
\rotatebox{90}{\textcolor{white}{Open source}}}
& \multicolumn{1}{c!{\color{white}\vline}@{}
!{\color{black!80}\vrule width 1ex}}{%
\rotatebox{90}{\textcolor{white}{\# operators}}} \\
\hline
\cellcolor{black!80}
& \cellcolor{black!40}{Tool1}
& Yes & 1 \\
\cellcolor{black!80}
& \cellcolor{black!40}{Tool2}
& Yes & 2 \\
\cellcolor{black!80}
\multirow{-3}{*}[-1ex]{\rotatebox{90}{Java}}
& \cellcolor{black!40}{Tool3}
& Yes & 3 \\
\rowcolor{black!80}
& & & \\
\hline
\end{tabu}
\end{document}
答案2
与。{NiceTabular}
nicematrix
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\setlength{\tabcolsep}{4pt}
\begin{NiceTabular}{ccccc}
\CodeBefore
\arraycolor{black}
\rectanglecolor{gray}{2-2}{4-2}
\rectanglecolor{white}{2-3}{4-4}
\rectanglecolor{gray!15}{3-3}{3-4}
\Body
\RowStyle[color=white]{\sffamily\rotate} & & Open source\; & \# operators & \\
\Block{3-1}{\color{white} \sffamily \rotate Java}
& Tool1 & Yes & 1 \\
& Tool2 & Yes & 2 \\
& Tool2 & Yes & 3 \\
\\
\CodeAfter
\tikz \draw [white] (1-|3) -- (2-|3) (1-|4) -- (2-|4) (1-|5) -- (2-|5) ;
\tikz \draw [gray!15] (3-|2) -- (3-|5) (4-|2) -- (4-|5) ;
\tikz \draw (2-|4) -- (5-|4) ;
\end{NiceTabular}
\end{document}