7

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}
16

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.

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.