[Tex/LaTex] How to indent text within a tabular environment

indentationrtables

I'm trying to create a table in r markdown where the age groups such as 0-20 and 21-55 are indented:

\documentclass{article}
\begin{document}
\begin{tabular}{lccc}
\toprule
Factors & 2 & 2 & P-Value\\
\midrule
Age\\
0-20 & 2 & 2 & 2\\
21-55 & 2 & 2 & 2\\
\bottomrule
\end{tabular}
\end{document}

I've tried using spaces, \indent, \hspace, \rowgroup (didn't compile in r markdown). Any help is greatly appreciated.

Best Answer

You could insert an \hspace{<some length>} directive at the start of cells. In the example below, I've set the length to 3mm; you're obviously free to choose a different length.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\noindent
\begin{tabular}{@{}lccc@{}}
\toprule
Factors & 2 & 2 & P-Value\\
\midrule
Age\\
\hspace{3mm}0--20 & 2 & 2 & 2\\
\hspace{3mm}21--55 & 2 & 2 & 2\\
\bottomrule
\end{tabular}
\end{document}