3

How can I center the text vertically in my table?

In the followong example "Number" and "Potential" are not centered vertically

Example:

\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

enter image description here

2

Don't use extrarowheight. As there's no \extrarowdepth, it won't be vertically centred. U used the cellspace package, which defines minimal vertical padding at the top and bottom of cells in columns with specifiers prefixed with the letter S, or C if you load siunitx – which I did, as the symbols for micrometers should be in upshape font. Also I took the liberty to change your grey to a nicer (for me) shade of grey. B.t.w., if you load xcolor with option [table], you don't have to load 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} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.