1

I want to display a table in latex. Currently I have the following situation.

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

enter image description here

The code outputs like the above. The problem is that, in two-column format, it leaves a lot of space on the right. I want my left most column to position from left, and all other columns to be positioned from the right. In that way, the white spaces will be minimized and the table will look decent. I have tried changing the column type. Doesn't work.

Any help is highly appreciated!

  • 1
    you should be using tabular not tabularx or use X not p columns (tabularx with no X columns does nothing useful) – David Carlisle Mar 30 '16 at 22:50
2

You have one column more than needed. I propose to use tabularx full column wide, and ragged2e. Added booktabs to have some vertical padding around horizontal rules, and reduced the value of \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} 

enter image description here

3

Some suggestions:

  • Instead of

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

    use

    \newcolumntype{P}{>{\raggedright\arraybackslash}X}
    
  • Instead of

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

    use

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

    The @{} particles serve to remove the whitespace that's otherwise inserted at the left-hand and right-hand edges of the tabular matter.

A full MWE:

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.