Add custom left spacing in a single LaTeX table's cell

Viewed 607

I need to add some left spacing in a table's cell. Can anyone help me?

It follows a code sample; I need to add left spacing in the cells of the first colum where the label is not bold.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{titlesec}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{graphics}

\begin{document}
{

\begin{table}[ht]
    \centering
    \setlength{\tabcolsep}{2pt}
    \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{|p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering\arraybackslash}p{0.15\textwidth}|}
        \hline
         & \textbf{VRE} & \textbf{FPE} & \textbf{MPE} & \multicolumn{2}{c|}{\textbf{Full sample}} \\ 
         & \textit{n} & \textit{n} & \textit{n} & \textit{n} & \textit{\%} \\
         \hline
         \textbf{Gender} &&&&& \\
         Female & 12 & 10 & 18 & 40 & 52.6 \\
         Male & 10 & 13 & 13 & 36 & 47.4 \\
         \hline
         \textbf{Educational level} &&&&& \\
         High School & 8 & 5 & 6 & 19 & 25.0 \\
         Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
         Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
         PhD & 0 & 1 & 0 & 1 & 1.3 \\
         \hline \hline
         \textbf{Age} &&&&& \\
         Mean & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
         Median & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
         \hline
    \end{tabular}
    \caption{Participants demographic information}
    \label{tab:demographic}
\end{table}

}

Thanks in advance.

1 Answers

One possibility: you can place \quad (or similar spacing macros) at the start of these cells:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{titlesec}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{graphics}

\begin{document}
{

\begin{table}[ht]
    \centering
    \setlength{\tabcolsep}{2pt}
    \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{|p{0.26\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering}p{0.15\textwidth}>{\centering\arraybackslash}p{0.15\textwidth}|}
        \hline
         & \textbf{VRE} & \textbf{FPE} & \textbf{MPE} & \multicolumn{2}{c|}{\textbf{Full sample}} \\ 
         & \textit{n} & \textit{n} & \textit{n} & \textit{n} & \textit{\%} \\
         \hline
         \textbf{Gender} &&&&& \\
         \quad Female & 12 & 10 & 18 & 40 & 52.6 \\
         \quad Male & 10 & 13 & 13 & 36 & 47.4 \\
         \hline
         \textbf{Educational level} &&&&& \\
         \quad High School & 8 & 5 & 6 & 19 & 25.0 \\
         \quad Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
         \quad Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
         \quad PhD & 0 & 1 & 0 & 1 & 1.3 \\
         \hline \hline
         \textbf{Age} &&&&& \\
         \quad Mean & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
         \quad Median & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
         \hline
    \end{tabular}
    \caption{Participants demographic information}
    \label{tab:demographic}
\end{table}

}

\end{document}

enter image description here


Unrelated to the problem, but your fixed width columns "waste" a lot of space. I would instead use a tabularx like this:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{titlesec}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{graphics}

\begin{document}
{

\begin{table}[ht]
    \centering
    \setlength{\tabcolsep}{10pt}
    \renewcommand{\arraystretch}{1.5}
    \begin{tabularx}{\textwidth}{ | X ccccc | }
        \hline
         & \textbf{VRE} & \textbf{FPE} & \textbf{MPE} & \multicolumn{2}{c|}{\textbf{Full sample}} \\ 
         & \textit{n} & \textit{n} & \textit{n} & \textit{n} & \textit{\%} \\
         \hline
         \textbf{Gender} &&&&& \\
         \quad Female & 12 & 10 & 18 & 40 & 52.6 \\
         \quad Male & 10 & 13 & 13 & 36 & 47.4 \\
         \hline
         \textbf{Educational level} &&&&& \\
         \quad High School & 8 & 5 & 6 & 19 & 25.0 \\
         \quad Bachelor's Degree & 13 & 9 & 19 & 41 & 53.9 \\
         \quad Master's Degree & 1 & 8 & 6 & 15 & 19.7 \\
         \quad PhD & 0 & 1 & 0 & 1 & 1.3 \\
         \hline \hline
         \textbf{Age} &&&&& \\
         \quad Mean & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
         \quad Median & 23.6 & 24.6 & 24 & \multicolumn{2}{c|}{24.1} \\
         \hline
    \end{tabularx}
    \caption{Participants demographic information}
    \label{tab:demographic}
\end{table}

}

\end{document}

enter image description here

Related