[Tex/LaTex] Vertically centered and right/left/center horizontal alignment in tabular

tables

I understand that vertically centering columns can be achieved by using the array package with the m{} column. How do I also specify horizontal alignment?

\documentclass[12pt,letterpaper]{article}

\usepackage{array}

\begin{document}
\begin{tabular}{m{5em} m{5em} m{5em}}
left & center & right
\end{document}

Best Answer

You can define new columns with the help of array package.

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}   %% centered
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}  %% right aligned

MWE:

\documentclass[12pt,letterpaper]{article}

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}

\begin{document}
\begin{tabular}{|m{5em}| C{5em}| R{5em}|}
left & center & right
\end{tabular}
\end{document}

enter image description here

I have added vertical lines just for the illustration of alignment. Don't use them | in your real document.

Related Question