4

in the MWE below, I wanted to be able to center the row entries vertically in the table. Thanks!

Here is my code:

\documentclass{book}
\usepackage{amsfonts}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{array}
\usepackage[svgnames,table]{xcolor}

\begin{document}

\chapter*{List of Abbreviations}

\begin{center}
\rowcolors{2}{cyan!25}{white}
\begin{tabular}{ m{3cm} m{7cm} }
\rowcolor{cyan!50}
\arrayrulecolor{white}
\arrayrulewidth=1pt
\renewcommand{\arraystretch}{1.5}
\textbf{Abbreviation} & \textbf{Explanation} \\ [2ex]
\textbf{ACPR} & Adjacent Channel Power Rejection \\ [2ex]
\textbf{BER} & Bit Error Rate \\ [2ex]
\textbf{EVM} & Error Vector Magnitude \\ [2ex]
\textbf{FM} & Frequency Modulation \\ [2ex]
\textbf{HP} & High Port \\ [2ex]
\textbf{IMR} & Inter Modulation Rejection \\ [2ex]
\end{tabular}
\end{center}

\end{document}
  • Do you expect multi line content of cells? – Zarko Feb 25 '16 at 17:49
3

Some suggestions:

  • Drop the [2ex] vertical spacing directives;

  • To compensate, increase \arraystretch to ca 1.75;

  • Use p rather than m column types; and

  • Omit the \arrayrulecolor{white} and \arrayrulewidth=1pt directives, as the code doesn't feature either horizontal or vertical lines.

enter image description here

\documentclass{book}
\usepackage[table]{xcolor}
\begin{document}

\begin{center}
\renewcommand{\arraystretch}{1.75}%
\rowcolors{2}{cyan!25}{white}
\begin{tabular}[t]{>{\bfseries}p{3cm} p{7cm}}
\rowcolor{cyan!50}
Abbreviation & Explanation \\ 
ACPR & Adjacent Channel Power Rejection \\ 
BER & Bit Error Rate \\ 
EVM & Error Vector Magnitude \\ 
FM & Frequency Modulation \\ 
HP & High Port \\ 
IMR & Inter Modulation Rejection \\ 
\end{tabular}
\end{center}

\end{document}

Addendum to address the OP's follow-up query: To have a thick white line separate the two header cells, add the instructions \arrayrulecolor{white} and \setlength{\arrayrulewidth}{2pt} before \begin{tabular} and change the first header cell from Abbreviation to \multicolumn{1}{l|}{\bfseries Abbreviation}.

  • @Micro, Thanks for your solution! Is there a way to add a thick white line to separate the Abbreviation and Explanation? Thanks again! – Joe Feb 25 '16 at 17:54
  • 1
    @joe - I've provided an addendum to my answer to address your follow-up query. – Mico Feb 25 '16 at 18:05
  • Sorry, I may have "mis-wrote"...how to place that thick white line all the way vertically down the table and not just the first row? Thanks again! – Joe Feb 25 '16 at 22:44
  • 1
    @Joe - Just change \begin{tabular}[t]{>{\bfseries}p{3cm} p{7cm}} to \begin{tabular}[t]{>{\bfseries}p{3cm} | p{7cm}}, after (of course) executing \arrayrulecolor{white} and \setlength{\arrayrulewidth}{2pt}. – Mico Feb 25 '16 at 23:01
3

Huh, @Mico was few second faster than me with almost the same solution, so I change mine slightly.

Edit: Since after upload of my answer, I reed your comment, that the cells wiuld be only with one line content, I reduce my solution to use p{...} type of columns. For better vertical aligning I also ad small trick with rule[...]{...}{...} and erase \arraystretch, see the code below:

\documentclass{book}
\usepackage{amsfonts}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{array}
\usepackage[svgnames,table]{xcolor}

\begin{document}
\chapter*{List of Abbreviations}
    \begin{center}
    \rowcolors{2}{cyan!25}{white}
\begin{tabular}{@{\hspace{\tabcolsep}\rule[-2.2ex]{0pt}{6ex}} >{\bfseries}p{3cm} p{7cm} }
\rowcolor{cyan!50}
Abbreviation    
                & \textbf{Explanation}              \\ 
ACPR            & Adjacent Channel Power Rejection  \\
BER             & Bit Error Rate                    \\
EVM             & Error Vector Magnitude            \\
FM              & Frequency Modulation              \\
HP              & High Port                         \\
IMR             & Inter Modulation Rejection        \\
\end{tabular}
    \end{center}
\end{document}

enter image description here

  • 2
    The typographic struts of height 6ex and depth 2.5ex may center the text mathematically, but not optically/aesthetically. (The eye wants to "see" a bit more space above the ascenders than below the descenders to achieve visual centering.) I'd increase the height of the struts and/or decrease the depth of the struts slightly. The struts seem to dominate the effect of setting \arraystretch to 1.5; omit that instruction? – Mico Feb 25 '16 at 18:11
  • 2
    Mico, meantime I adjust used strut a bit. To be honest, its use is introduced that my answer differ a bit from yours, however after some tweaking of strut size in my ayes it provide better optical centering than is obtained by array stretch. Probably I'm wrong (my ayes recently are so tired ... ) – Zarko Feb 25 '16 at 20:02

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.