平均能量损失

平均能量损失

我尝试改进下表,如下面的屏幕截图所示,输出大部分是我想要的。

在此处输入图片描述

当文本跨越多行时,为什么文本没有垂直居中?我原本以为结果应该是这样的

在此处输入图片描述

也欢迎使用任何其他方法来获得相同的输出。我觉得我的解决方案是让标题和第一列加粗,即使我喜欢这个输出,也有点复杂。同样,也许存在一种更简单的方法来垂直居中文本并定义单元格的最小高度?

平均能量损失

\documentclass[10pt,a4paper]{article}
\usepackage[margin=1.3in]{geometry} 
\usepackage{array,booktabs,lipsum}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\newcolumntype{C}{ >{\vbox to 5ex\bgroup\vfill\centering\arraybackslash}X<{\egroup} }
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\newcommand{\low}{\cellcolor{green!50}}
\newcommand{\med}{\cellcolor{yellow!50}}
\newcommand{\high}{\cellcolor{red!50}}

\begin{document}
\lipsum[66]
\begin{table}[htbp]
\centering
\scriptsize
\def\arraystretch{1.5}%
\caption{Initial risk matrix}
\begin{tabularx}{\textwidth}{| >{\bfseries}C | ^C | ^C | ^C | ^C | ^C |}
\hline \rowstyle{\bfseries}
Frequency/ Consequence & 1-Very Unlikely & 2-Remote & 3-Occasional & 4-Probable & 5-Frequent\\ 
\hline 4-Catastrophic & Auto-ignition \med & Toxic release \high & \high & \high &\high \\
\hline 3-Critical &\low & \med & \med & \high Refuelling systems & \high \\ 
\hline 2-Major & \low & \low & \med & Fire spread from nearby buses \med &\high \\ 
\hline 1-Minor & \low & \low & \low &\med &\med \\ 
\hline
\end{tabularx} \\
\end{table}
\lipsum[75]
\end{document}

答案1

我提出了这个基于 的解决方案,它在以字母(或您使用选项选择的任何字母)cellspace为前缀的说明符的列中单元格顶部和底部定义了最小垂直填充。我只需要使用自定义单元格。S[column= some letter]X

\documentclass[10pt,a4paper]{article}
\usepackage[margin=1.3in]{geometry}
\usepackage{array,booktabs,lipsum}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{>{\centering\arraybackslash}m{#1}}%
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\newcommand{\low}{\cellcolor{green!50}}
\newcommand{\med}{\cellcolor{yellow!50}}
\newcommand{\high}{\cellcolor{red!50}}

\usepackage[skip=6pt]{caption}
\usepackage[column=O]{cellspace}
\addparagraphcolumntypes{X}
\setlength{\cellspacetoplimit}{6pt}
\setlength{\cellspacebottomlimit}{6pt}

\begin{document}

\lipsum[66]
\begin{table}[htbp]
\centering
\scriptsize
\def\arraystretch{1.5}%
\caption{Initial risk matrix}
\begin{tabularx}{\textwidth}{| >{\bfseries}O{X} | ^X | ^X | ^X | ^X | ^X |}
\hline \rowstyle{\bfseries}
Frequency/ Consequence & 1-Very Unlikely & 2-Remote & 3-Occasional & 4-Probable & 5-Frequent\\
\hline 4-Catastrophic & Auto-ignition \med & Toxic release \high & \high & \high &\high \\
\hline 3-Critical &\low & \med & \med & \high Refuelling systems & \high \\
\hline 2-Major & \low & \low & \med & Fire spread from nearby buses \med &\high \\
\hline 1-Minor & \low & \low & \low &\med &\med \\
\hline
\end{tabularx} \\
\end{table}
\lipsum[75]

\end{document} 

在此处输入图片描述

相关内容