# How do I indent text within a tabular environment?

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.

• Welcome to TeX.SE. Please tell us by how much certain cells should be indented. Incidentally, did you mean "indented" or "right-aligned"? – Mico Mar 21 '17 at 20:39
• indented over a few characters, so that it looks like the age groups are a subset of Age – guest_123 Mar 21 '17 at 20:43
• you have specified that the first column is flush left, you could use c instead, or use \  or ... – David Carlisle Mar 21 '17 at 20:56

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.

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


A slight improvement for the alignment of the left column (on the endash):

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\noindent
\begin{tabular}{@{}rccc@{}}
\toprule
\multicolumn{1}{l}{Factors\hspace*{0.25em}} & 2 & 2 & P-Value\\
\midrule
\multicolumn{1}{l}{Age}\\
0--20 & 2 & 2 & 2\\
21--55 & 2 & 2 & 2\\
\bottomrule
\end{tabular}

\end{document}


• +1. I thought about aligning the age groups on the en-dash symbols as well, but I didn't do so as the OP didn't seem to care about this aspect of the table. I think your solution looks better... – Mico Mar 21 '17 at 22:27

For me I like the simplicity of @Bernard and the indentation of @Mico, so I combined the two solutions:

    \begin{tabular}{@{\hspace*{1.8em}}lccc@{}}
\toprule
\multicolumn{1}{l}{Factors\hspace*{-1.8em}} & 2 & 2 & P-Value\\
\midrule
\multicolumn{1}{l}{Age}  & 2 & 2 & P-Value\\
0--20  & 2 & 2 & 2\\
21--55 & 2 & 2 & 2\\
\bottomrule
\end{tabular}