如何从最右边距设置乳胶表列?

如何从最右边距设置乳胶表列?

我想在 latex 中显示一个表格。目前我有以下情况。

\usepackage{array}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{table}[h!]
\begin{tabularx}{0.45\textwidth}{P{3.2cm}*{5}{r}r} %{l*{5}{c}c}
\textbf{Statement}              & \textbf{P1} & \textbf{P2} & \textbf{P3} & \textbf{P4} & \textbf{P5} \\
\hline
The overall experience was enjoyable & 4 & 4 & 4 & 5 & 3  \\
Learning cricket was easy & 5 & 5 & 5 & 5 & 5 \\
\hline
\textit Cricket was user-friendly           & 3 & 3 & 4 & 4 &  2   \\
Using the bat was easy           & 5 & 4 & 5 & 5 & 4  \\
Using the balls was easy     & 5 & 5 & 4 & 3 &  4 \\
\hline
Cricket was easier than current system & 3 & 2 & 3 & 3 & 2 \\
I will play cricket in future & 3 & 4 & 4 & 4 & 3 \\
\end{tabularx}
\caption{Results from the questionnaire on 5-point Likert scale}
\label{tab:questionnaire}
\end{table}

在此处输入图片描述

代码输出结果与上述类似。问题是,在双列格式中,右侧会留出大量空间。我希望最左边的列从左侧定位,而所有其他列从右侧定位。这样,空白将最小化,表格看起来会不错。我尝试过更改列类型。没有用。

非常感谢您的帮助!

答案1

您多了一列。我建议使用tabularx整列宽度,并且ragged2ebooktabs在水平规则周围添加一些垂直填充,并减少的值\tabcolsep

\documentclass[twocolumn]{article}
\usepackage[showframe]{geometry}%
\usepackage{lipsum}
\usepackage{ragged2e}
\usepackage{array, tabularx, caption, booktabs}
\begin{document}

\lipsum[1]
\begin{table}[h!]
  \setlength\tabcolsep{3pt}
  \begin{tabularx}{\linewidth}{@{} >{\RaggedRight}X*{5}{c}@{}} %{l*{5}{c}c}
    \textbf{Statement} & \textbf{P1} & \textbf{P2} & \textbf{P3} & \textbf{P4} & \textbf{P5} \\
    \toprule
    The overall experience was enjoyable & 4 & 4 & 4 & 5 & 3 \\
    Learning cricket was easy & 5 & 5 & 5 & 5 & 5 \\
    \midrule
    \textit Cricket was user-friendly & 3 & 3 & 4 & 4 & 2 \\
    Using the bat was easy & 5 & 4 & 5 & 5 & 4 \\
    Using the balls was easy & 5 & 5 & 4 & 3 & 4 \\
    \midrule
    Cricket was easier than current system & 3 & 2 & 3 & 3 & 2 \\
    I will play cricket in future & 3 & 4 & 4 & 4 & 3 \\
    \bottomrule
  \end{tabularx}
  \caption{Results from the questionnaire on 5-point Likert scale}
  \label{tab:questionnaire}
\end{table}

\end{document} 

在此处输入图片描述

答案2

一些建议:

  • 代替

    \newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
    

    使用

    \newcolumntype{P}{>{\raggedright\arraybackslash}X}
    
  • 代替

    \begin{tabularx}{0.45\textwidth}{P{3.2cm}*{5}{r}r}
    

    使用

    \centering
    \begin{tabularx}{0.6\textwidth}{@{}P *{5}{r} @{}}
    

    这些@{}粒子的作用是删除表格内容左侧和右侧边缘插入的空白。

完整的 MWE:

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{P}{>{\raggedright\arraybackslash}X}

\begin{document}

\begin{table}[h!]
\centering
\begin{tabularx}{0.6\textwidth}{@{}P *{5}{r} @{}}
\textbf{Statement}  & \textbf{P1} & \textbf{P2} & \textbf{P3} & \textbf{P4} & \textbf{P5} \\
\midrule
The overall experience was enjoyable & 4 & 4 & 4 & 5 & 3  \\
Learning cricket was easy & 5 & 5 & 5 & 5 & 5 \\
\midrule
\textit Cricket was user-friendly & 3 & 3 & 4 & 4 &  2 \\
Using the bat was easy       & 5 & 4 & 5 & 5 & 4  \\
Using the balls was easy     & 5 & 5 & 4 & 3 &  4 \\
\midrule
Cricket was easier than the current system & 3 & 2 & 3 & 3 & 2 \\
I will play cricket in the future & 3 & 4 & 4 & 4 & 3 \\
\bottomrule
\end{tabularx}
\caption{Results from the questionnaire on 5-point Likert scale}
\label{tab:questionnaire}
\end{table}
\end{document}

相关内容