# How to vertically align text in table cell?

Here is the latex code to create a table in BibTxtMng

 \begin{table}[!htbp]
\centering
\caption{Spanish Traffic Sign according to the color and shape \cite{Paper12}}
\begin{tabular}{|>{\raggedright}p{3.1cm}|>{\raggedright}p{3.1cm}|>
{\raggedright}p{3.1cm}|}
\hline
Color          & Shape    & Meaning \tabularnewline
\hline
Red Rim        & Circle   & Prohibition\tabularnewline
\hline
Red Rim (Up)   & Triangle & Danger      \tabularnewline
\hline
Red Rim (Down) & Triangle & Yield       \tabularnewline
\hline
Red            & Octagonal & Stop\tabularnewline
\hline
Blue  & Square &  Recommendation \tabularnewline
\hline
Blue &    Circle &    Obligation \tabularnewline
\hline
White  & Circle    & End of Prohibition \tabularnewline
\hline
Yellow & Circle & End of Prohibition (construction)\tabularnewline
\hline
\end{tabular}
\label{Spanish_TS}
\end{table}


Here is the output table I got

I want that yellow and circle text (in the last row) being located in the centre of vertical. Not tin the top like that..

How to do it??

-

You can use m column specifier for the last cell in last row.

\documentclass{article}
\usepackage{array}             %% you need this
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Spanish Traffic Sign according to the color and shape \cite{Paper12}}
\begin{tabular}{|>{\raggedright}p{3.1cm}|>{\raggedright}p{3.1cm}|>
{\raggedright}p{3.1cm}|}
\hline
Color          & Shape    & Meaning \tabularnewline
\hline
Red Rim        & Circle   & Prohibition\tabularnewline
\hline
Red Rim (Up)   & Triangle & Danger      \tabularnewline
\hline
Red Rim (Down) & Triangle & Yield       \tabularnewline
\hline
Red            & Octagonal & Stop\tabularnewline
\hline
Blue  & Square &  Recommendation \tabularnewline
\hline
Blue &    Circle &    Obligation \tabularnewline
\hline
White  & Circle    & End of Prohibition \tabularnewline
\hline
Yellow & Circle & \multicolumn{1}{|m{3.1cm}|}{End of Prohibition (construction)}\tabularnewline
\hline
\end{tabular}
\label{Spanish_TS}
\end{table}
\end{document}


You may use the m column specifier for all columns if you have variable width text in them to have vertical alignment.

-
Or even in all columns. – egreg Apr 1 '14 at 13:44
@egreg probably yes, to be on the safer side. :) – Harish Kumar Apr 1 '14 at 13:45

If you are willing to manually do the linebreaks within a row yourself, you can use a \Centerstack, as shown here. In that case though, the p columns are not really needed, unless you want them for their width. You can dispense with them by deleting that declaration and uncommenting the 3 other lines in my code.

\documentclass{article}
\usepackage{array}
\usepackage[usestackEOL]{stackengine}
%\edef\tmp{\the\baselineskip}
%\setstackgap{L}{\tmp}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Spanish Traffic Sign according to the color and shape \cite{Paper12}}
%\begin{tabular}{|l|l|l|}
\begin{tabular}{|>{\raggedright}p{3.1cm}|>{\raggedright}p{3.1cm}|>{\raggedright}p{3.1cm}|}
\hline
Color          & Shape    & Meaning \tabularnewline
\hline
Red Rim        & Circle   & Prohibition\tabularnewline
\hline
Red Rim (Up)   & Triangle & Danger      \tabularnewline
\hline
Red Rim (Down) & Triangle & Yield       \tabularnewline
\hline
Red            & Octagonal & Stop\tabularnewline
\hline
Blue  & Square &  Recommendation \tabularnewline
\hline
Blue &    Circle &    Obligation \tabularnewline
\hline
White  & Circle    & End of Prohibition \tabularnewline
\hline
Yellow & Circle & \Centerstack[l]{End of\\ Prohibition\\ (construction)}\tabularnewline
\hline
\end{tabular}
\label{Spanish_TS}
\end{table}
\end{document}


-