如何使表格中的文本垂直居中?
在以下示例中,“Number”和“Potential”未垂直居中
例子:
\documentclass[fleqn, listof=totoc, bibliography=totoc, a4paper, fontsize=12pt, headsepline, oneside, openright]{scrbook}
\usepackage{xcolor}
\usepackage{booktabs,colortbl,tabularx}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\extrarowheight}{.75ex}
\begin{document}
\begin{table}[H]
\centering
\caption{caption}
\label{tab:potential}
\begin{tabular}{cc}
\toprule
\rowcolor{lightgray}
Number & Potential \\
\midrule
01& 681 $\mu{}m$\\
02& 688 $\mu{}m$\\
03& 702 $\mu{}m$\\
04& 716 $\mu{}m$\\
05& 701 $\mu{}m$\\
06& 815 $\mu{}m$\\
\bottomrule
\end{tabular}
\end{tab
答案1
不要使用extrarowheight
。因为没有\extrarowdepth
,它不会垂直居中。你使用了cellspace
包,它定义了最小在以字母 为前缀的说明符的列中,单元格顶部和底部的垂直填充S
,或者C
如果您加载siunitx
- 我这样做了,因为微米的符号应该采用 upshape 字体。此外,我还擅自将您的灰色更改为更漂亮的灰色(对我来说)。顺便说一句,如果您使用xcolor
选项加载[table]
,则不必加载colortbl
:
\documentclass[fleqn, listof=totoc, bibliography=totoc, a4paper, fontsize=12pt, headsepline, oneside, openright]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[table, svgnames]{xcolor}
\usepackage{booktabs,tabularx, float}
\usepackage{siunitx}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\usepackage{cellspace}
\setlength\cellspacetoplimit{6pt}
\setlength\cellspacebottomlimit{6pt}
\begin{document}
\begin{table}[H]
\centering
\caption{caption}
\label{tab:potential}
\begin{tabular}{CcCc}
\toprule
\rowcolor{Lavender!75!lightgray}
Number & Potential \\
\midrule
01 & \SI{681}{\um} \\
02 & \SI{688}{\um} \\
03 & \SI{702}{\um} \\
04 & \SI{716}{\um} \\
05 & \SI{701}{\um} \\
06 & \SI{815}{\um} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}