2

I'm trying to make a table with the cells centered vertically. Any solution I've found is giving me errors or not working.

Here is a minimally working version of my code:

 \documentclass[10pt,a4paper]{article}
 \usepackage[left=1.00in, right=1.00in, top=1.00in, bottom=1.00in]{geometry}
 \begin{document}
 \begin{tabular}{| *7{p{2cm}|}}
        \hline
         SWIPES & \multicolumn{3}{c|}{ALPHA ACTIVITY DETERMINATIONS} & \multicolumn{3}{c|}{BETA ACTIVITY DETERMINATIONS} \\[2ex] \hline
        \normalsize Sample No. & Gross Count Rate (cpm) & Net Count Rate (cpm) & Activity (DPM) & Gross Count Rate (cpm) & Net Count Rate (cpm) & Activity (DPM) \\[2ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
        &                        &                      &                &                        &                      &                \\[1.5ex] \hline
\end{tabular}
\end{document}

It outputs a table that looks like this: enter image description here

Here is what I want it to look like. The double lines aren't required but if you know how to add them I would appreciate it. enter image description here

My biggest problem with the format is the fact that the titles with beta and alpha in them aren't really centered vertically. Thank you in advance for any help you can give.

  • 1
    In the preamble \usepackage{array} and then \begin{tabular}{| *7{>{\centering\arraybackslash}p{2cm}|}}...\end{tabular}. – Gonzalo Medina Mar 10 '15 at 16:13
5

For centering the column contents, load the array package \usepackage{array} and then use

\begin{tabular}{| *7{>{\centering\arraybackslash}p{2cm}|}}
...
\end{tabular}

Use the hhline package for the double lines:

 \documentclass[10pt,a4paper]{article}
 \usepackage[left=1.00in, right=1.00in, top=1.00in, bottom=1.00in]{geometry}
\usepackage{array}
\usepackage{hhline}

 \begin{document}

 { 
 %\renewcommand\arraystretch{1.3}
 \setlength\extrarowheight{5pt}
 \begin{tabular}{
 || >{\centering\arraybackslash}p{2cm}
 | >{\centering\arraybackslash}p{2cm}
 | >{\centering\arraybackslash}p{2cm}
 | >{\centering\arraybackslash}p{2cm}
 || >{\centering\arraybackslash}p{2cm}
 | >{\centering\arraybackslash}p{2cm}
 | >{\centering\arraybackslash}p{2cm}||
 }
        \hhline{|t:====:t:===:t|}
         SWIPES & \multicolumn{3}{c||}{ALPHA ACTIVITY DETERMINATIONS} & \multicolumn{3}{c||}{BETA ACTIVITY DETERMINATIONS} \\[2ex] 
                 \hhline{|:====::===:|}
        \normalsize Sample No. & Gross Count Rate (cpm) & Net Count Rate (cpm) & Activity (DPM) & Gross Count Rate (cpm) & Net Count Rate (cpm) & Activity (DPM) \\[2ex] 
\hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex] \hhline{||----||---||}
        &                        &                      &                &                        &                      &                \\[1.5ex]         \hhline{|b:====:b:===:b|}
\end{tabular}
}

\end{document}

enter image description here

Remarks:

  • Vertical rules are not really necessary; perhaps you could be interested in the booktabs package to improve the quality of your table.

  • For vertically centered cells, use m{<length>} instead of p{<length>} columns.

  • You can change \arraystretch and/or \extrarowheight to have some more air around cells contents.

  • Is there anyway to get the first row of text with swipes, alpha and beta in them to be vertically centered or at least have some space off the top line? – heyjva Mar 10 '15 at 16:24
  • @heyjva I think this is an answer to a different question. You asked about vertical centring but this does horizontal centring. Have I understood your question correctly? – cfr Mar 10 '15 at 16:27
  • @heyjva Please see my updated answer. I also included the case in which you wanted vertically centered columns. – Gonzalo Medina Mar 10 '15 at 16:30

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.