LaTeX table 中固定列宽的居中元素

Centering element in LaTeX table with fixed column width

我在使用 LaTeX tables 时遇到了一些问题。特别是,我有以下代码:

\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}p{0.15\textwidth}|}
        \hline
         & \textbf{Virtual Reality Experience} & \textbf{First Person Experience} & \textbf{Multimedia Presentation Experience} & \multicolumn{2}{c|}{\textbf{Full sample}} \ 
         \hline
         & \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}

这段代码给出了以下输出: generated table.

我也想将最后一列居中(与其他列一样,使用 >{\centering} )。但是,当我尝试这样做时,出现了很多错误:

有人能帮帮我吗?如果我设法将最后一行居中,table 会更漂亮。

您可以将最后一列居中 >{\centering\arraybackslash}

\documentclass{article}

\usepackage{array}

\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{Virtual Reality Experience} & \textbf{First Person Experience} & \textbf{Multimedia Presentation Experience} & \multicolumn{2}{c|}{\textbf{Full sample}} \ 
         \hline
         & \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}


\end{document}