# How to center vertically content of the table?

I have this table:

\usepackage{array}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}

\begin{table}[ht]\footnotesize
\centering
\begin{tabular*}{0.95\textwidth }{@{\extracolsep{\fill}}|llllllllllllllll|x{0.15\textwidth}|}
\hline
\multicolumn{16}{|c|}{Small text} & Long text \\ \hline
1 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 16 & 19 & 20 & 21 & 22 & 23 & 0.9636149 \\ \hline
\end{tabular*}
\caption{Caption}
\label{tab:Example}
\end{table}


How to center "Small text"?

• I can't compile your example. What table-extending packages are you using? Nov 7, 2010 at 19:38
• Sorry, I haven't included my custom column definition. Now it should compile. Nov 7, 2010 at 19:45
• Works for me, sort of. With the standard article class the lines don't extend all the way across, because the table is too wide for the \textwidth. If I do \usepackage[letterpaper]{geometry} which shortens the margins a bit, the lines extend all the way across. Either way, though, "small text" is centered across the first 16 columns. Can you post a picture of what you're seeing? Nov 7, 2010 at 19:54
• @Matthew: I think the important word here is vertical. Think of ”long text” as something that has multiple lines. Then “small text” is aligned at the top. Nov 7, 2010 at 20:20
• Ah. I might have realized that if "long text" had actually been long text. :) Nov 7, 2010 at 21:21

Change the p to m in your definition of the x column type:

\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}


Full example:

\documentclass{article}
\usepackage{array}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}

\begin{table}[ht]\footnotesize
\centering
\begin{tabular*}{0.95\textwidth }{@{\extracolsep{\fill}}|llllllllllllllll|x{0.15\textwidth}|}
\hline
\multicolumn{16}{|c|}{Small text} & Long long long long long text \\ \hline
1 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 16 & 19 & 20 & 21 & 22 & 23 & 0.9636149 \\ \hline
\end{tabular*}
\caption{Caption}
\label{tab:Example}
\end{table}
\end{document}

• How one would redefine \newcolumntype above to vertically align to the top of the cells? Jan 9 at 23:57
\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{amsmath}
\begin{document}

\begin{table}[h!]
\centering
\begin{tabular}{ | c | m{5cm} | m{5cm} | }
\hline
11111111 & 2222222 & 33333333 \\ \hline
\begin{minipage}{.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a.png}
\end{minipage}
&
\begin{equation*}
\dfrac{12!-x^2}{9x^3-99}
\end{equation*}
&
\begin{itemize}
\item item111
\item item2222222
\item text text text