[Tex/LaTex] Latex multicolumn vertical center

horizontal alignment

I have been trying numerous ways to get the vertical centering on the Latex table I'm working on. But it always gives a horizontally centered yet vertically on top alignment. what can I do to make it vertically centered?

\begin{center}
\centering
\begin{tabular}{|p{5in}|p{.5in}|} \hline
\multicolumn{2}{|c|}{\textbf{Grade 11}} \\ [2ex] \hline
Accounting & \cellcolor{Red}Failed \\ \hline
Maths & \cellcolor{Red}Failed \\ \hline
Science & \cellcolor{Red}Failed \\ \hline
\multicolumn{2}{|c|}{\textbf{Grade 12}} \\ [2ex] \hline
Accounting & \cellcolor{Red}Failed \\ \hline
\hline
\end{tabular}
\end{center}

-------------------------------------
              Grade 11


------------------------------------- 

I need this to come on the center (horizontally and vertically):

-------------------------------------

               Grade 11

-------------------------------------

Best Answer

I don't see the problem when all is wrapped in the table environment and the booktabs package is used. (If you have a comprehensive Latex installation it should be on the system.) It is one of the packages for tables that is easily recommended.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{booktabs}

\begin{table*}[!tb]
\centering
{ % scope the arraystretch command below
\renewcommand{\arraystretch}{1.5}

\begin{tabular}{ @{} p{5in} p{0.5in} @{} }  \toprule    
\multicolumn{2}{c}{ \textbf{Grade 11} } \\  \midrule 
Accounting & Failed \\ 
Maths      & Failed \\                      \bottomrule 
\end{tabular} 

} % end of \arraystretch scope. 
\caption{ An example table } 
\end{table*} 

I also pull rows apart a little more by renewing \arraystretch (only within the block), and I add @{} which remove the extra space on left and right. None of this is necessary. I dropped vertical lines, which can be added as usual. I don't have the coloring as it didn't work for me. The horizontal lines given by \toprule and \midrule have different thickness, which can also be adjusted.

Note: I don't know why the figure isn't centered here. The table is centered in the document.

table_example


If you would rather just directly fix what you have, you need to add the spacing above the line manually -- the spacing below has been added manually as well (the \\[2ex]). Just add an extra line, right above the multicolumn line

\multicolumn{2}{|c|}{ } \\                                % add this
\multicolumn{2}{|c|}{\textbf{Grade 11}} \\[2ex] \hline
 % ...

However, I can readily recommend booktabs for making tables look better. You can still tweak spacing if you wish, but that is far less likely to be needed. Another package that is commonly recommended for tables is array.