# How to align text vertically and horizontally in table cells of the same column?

I want to top align and right justify the text in all tabularx cells of a certain column. So far, I tried:

\documentclass[a4paper,10pt]{article}

\usepackage[top=2cm,bottom=2cm,right=2cm,left=3cm]{geometry}
\geometry{a4paper}
\usepackage{array}
\usepackage{tabularx}
\usepackage{ragged2e}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash\hspace{0pt}}p{#1}}

\begin{document}

\begin{tabularx}{\textwidth}{|R{2cm}|X|} \hline
A text on multiple lines & \shortstack{Line1 \\ Line2 \\ Line3 \\Line4 \\ Line5} \\ \hline
\end{tabularx}

\end{document}


And the output looks like this:

\RaggedLeft command seems to override the top alignment of p{'size'} column type in array package. How can I solve this problem?

• Welcome to TeX.SX! That \hspace isn't very well there. In addition, I suggest to use the multirow - package – user31729 Aug 5 '15 at 7:29
• Thank you! I removed the \hspace{0pt}, it did not solve the problem – Cristi Aug 5 '15 at 7:31

A trial solution, since I don't know the first column should be aligned really:

\documentclass[a4paper,10pt]{article}

\usepackage[top=2cm,bottom=2cm,right=2cm,left=3cm]{geometry}
\geometry{a4paper}
\usepackage{array}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{multirow}
\usepackage{makecell}
\newcolumntype{R}[1]{>{\RaggedLeft}p{#1}}

\begin{document}

\begin{tabularx}{\textwidth}{|R{2cm}|X|}
\hline
\multirow{5}{*}{\makecell[rt]{A text on\\ multiple lines}} & Line1 \tabularnewline
& Line2  \tabularnewline
& Line3 \tabularnewline
& Line4 \tabularnewline
& Line5 \tabularnewline
\hline
\end{tabularx}

\begin{tabularx}{\textwidth}{|R{2cm}|X|}
\hline
\multirowcell{1}[0pt][tR{2cm}]{A text on  multiple lines} & Line1 \tabularnewline
& Line2  \tabularnewline
& Line3 \tabularnewline
& Line4 \tabularnewline
& Line5 \tabularnewline
\hline
\end{tabularx}

\end{document}


• I think about the alignment of the first column – user31729 Aug 5 '15 at 7:38