[Tex/LaTex] How to adjust alignment and column width (tabular)

aligntables

I would like columns 2 and 3 to be aligned to the right hand side. However, it does not seem to work.
Though several questions relate to this issue and my question will probably be marked as duplicate, I don't know what is wrong about my table.

I would be thankful for any hints, e.g. on possibly missing packages.

\documentclass{article}
\usepackage{tabularx}                           
\begin{document}
   \begin{table}[htbp]
\begin{tabular}{p{0.1\textwidth}>{\raggedright\arraybackslash}p{0.05\textwidth}>{\raggedright\arraybackslash}p{0.05\textwidth}}
\hline
& h\_1 & h\_2  \\ 
\hline
x\_1 & 10.80 & 11.68 \\ 
x\_2 & 1.96 & 1.94 \\ 
\end{tabular}
\end{table}
\end{document}

Best Answer

Your columns are too narrow for the data, latex warns:

Overfull \hbox (5.5268pt too wide) in paragraph at lines 9--9
[]|\OT1/cmr/m/n/10 10.80|  

Overfull \hbox (5.5268pt too wide) in paragraph at lines 9--10
[]|\OT1/cmr/m/n/10 11.68|  

Overfull \hbox (0.52678pt too wide) in paragraph at lines 10--10
[]|\OT1/cmr/m/n/10 1.96| 

It can not align unbreakable text that is wider than the specified column width

It works if the columns are wider, also you want \raggedleft

\documentclass{article}
\usepackage{tabularx}                           
\begin{document}
   \begin{table}[htbp]
\begin{tabular}{p{0.2\textwidth}>{\raggedleft\arraybackslash}p{0.1\textwidth}>{\raggedleft\arraybackslash}p{0.1\textwidth}}
\hline
& h\_1 & h\_2  \\ 
\hline
x\_1 & 10.80 & 11.68 \\ 
x\_2 & 1.96 & 1.94 \\ 
\end{tabular}
\end{table}
\end{document}

Although for numeric columns it is usually better to use dcolumn or siunitx to align on the decimal point.