我想在表格的顶行添加一条对角线,而第一行上的其他条目都是横向书写的。我尝试过 \backslashbox 和 \diagbox 和 \diag,但无论我如何更改值,如果不提升所有其他条目,该线的最顶端位置都不会增加。
\usepackage{slashbox}
\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{tabular}{|l|c|c|c|}
\hline\hline
\backslashbox[130pt]{Property}{Concept} & \begin{sideways} Concept 1 \end{sideways} & \begin{sideways} Next concept \end{sideways} &
\begin{sideways} Next concept/increase line{\ } \end{sideways} \\
\hline
Do this & 0 & 0 & - \\
Do that & 0 & 0 & 0 \\
Do it quickly & 0 & + & + \\
Do the task quickly & 0 & 0 & - \\
\hline
SUM: & 0 & +1 & +2 \\
\hline
Ranking & 2 & 2 & 1 \\
\hline
Keep & NO & NO & YES \\
\hline\hline
\end{tabular}
\label{tab:Pugh_matrix2}
\end{table}
答案1
我使用diagbox
而不是slashbox
和rotatebox
来自的宏来graphicx
代替rotating
包:
\documentclass{article}
\usepackage{diagbox}
\usepackage{rotating}
\usepackage{graphicx}
\begin{document}
\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{tabular}{|l|c|c|c|}
\hline\hline
\diagbox[dir=NW]{\rule{0mm}{4cm}Property}{Concept} & \rotatebox[x=2cm]{90}{Concept 1} & \rotatebox[x=2cm]{90}{Next concept} &
\rotatebox[x=2cm]{90}{Next concept/increase line\ } \\
\hline
Do this & 0 & 0 & - \\
Do that & 0 & 0 & 0 \\
Do it quickly & 0 & + & + \\
Do the task quickly & 0 & 0 & - \\
\hline
SUM: & 0 & +1 & +2 \\
\hline
Ranking & 2 & 2 & 1 \\
\hline
Keep & NO & NO & YES \\
\hline\hline
\end{tabular}
\label{tab:Pugh_matrix2}
\end{table}
\end{document}
答案2
我建议使用另一种解决方案,它基于\rotcell
中的命令makecell
,允许在单元格中换行。此外,由于该包的存在,表格也得到了各种改进,尤其是标题和表格之间的垂直填充caption
。
\documentclass{article}
\usepackage{diagbox}
\usepackage{rotating}
\usepackage{graphicx}
\usepackage{makecell, caption, booktabs}
\begin{document}
\begin{table}[ht]
\centering\settowidth\rotheadsize{Next concept/}
\renewcommand\cellalign{cl}
\renewcommand\arraystretch{1.25}
\caption{Pugh matrix}
\begin{tabular}{|l|c|c|c|c}
\toprule\noalign{\vskip-1pt}\hline
\diagbox[height=1.25\rotheadsize]{\raisebox{3ex}{Property}}{\raisebox{-4ex}{Concept}} & \rotcell{Concept 1} & \rotcell{Next concept} & \rotcell{Next concept/ \\increase line} \\
\hline
Do this & 0 & 0 & $ - $ \\
Do that & 0 & 0 & 0 \\
Do it quickly & 0 & + & + \\
Do the task quickly & 0 & 0 & $ - $ \\
\hline
SUM: & 0 & +1 & +2 \\
\hline
Ranking & 2 & 2 & 1 \\
\hline
Keep & NO & NO & YES \\
\hline\bottomrule
\end{tabular}
\label{tab:Pugh_matrix2}
\end{table}
\end{document}
答案3
环境{NiceTabular}
有nicematrix
一个内置命令\diagbox
。使用该工具,您可以直接获得预期的输出。
\documentclass{article}
\usepackage{nicematrix,caption}
\begin{document}
\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{NiceTabular}{lccc}[vlines]
\hline
\diagbox{Property}{Concept} &
\RowStyle[cell-space-top-limit=3pt]{\rotate}
Concept 1 & Next concept & Next concept/increase line \\
\hline
Do this & $0$ & $0$ & $-$ \\
Do that & $0$ & $0$ & $0$ \\
Do it quickly & $0$ & $+$ & $+$ \\
Do the task quickly & $0$ & $0$ & $-$ \\
\hline
SUM: & $0$ & $+1$ & $+2$ \\
\hline
Ranking & $2$ & $2$ & $1$ \\
\hline
Keep & NO & NO & YES \\
\hline
\end{NiceTabular}
\label{tab:Pugh_matrix2}
\end{table}
\end{document}
如果您确实想在表格上方和下方放置双线规则,则会出现一个小问题。如果您\hline\hline
在表格上方使用双线规则,对角线规则的左上角位置将不正确。这就是为什么在下面的代码中,我使用 Tikz(使用由 创建的 PGF/Tikz 节点)在表格上方绘制了第一条规则nicematrix
。
\documentclass{article}
\usepackage{nicematrix,caption,tikz}
\begin{document}
\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{NiceTabular}{lccc}[vlines]
\Hline
\diagbox{Property}{Concept} &
\RowStyle[cell-space-top-limit=3pt]{\rotate}
Concept 1 & Next concept & Next concept/increase line \\
\Hline
Do this & $0$ & $0$ & $-$ \\
Do that & $0$ & $0$ & $0$ \\
Do it quickly & $0$ & $+$ & $+$ \\
Do the task quickly & $0$ & $0$ & $-$ \\
\Hline
SUM: & $0$ & $+1$ & $+2$ \\
\Hline
Ranking & $2$ & $2$ & $1$ \\
\Hline
Keep & NO & NO & YES \\
\Hline
\Hline
\CodeAfter
\tikz \draw ([yshift=\doublerulesep]1-|1) -- ([yshift=\doublerulesep]1-|last) ;
\end{NiceTabular}
\label{tab:Pugh_matrix2}
\end{table}
\end{document}