2

I want to adjust a column of a table, such that the heading is centred, the rest rows are left aligned, which I managed myself (see figure). Now, all rows have an additional attribute (length), which I want to be pushed to the extreme right of each cell. I tried with \hfil, but they are now centred in the space (not right aligned).

How can I do that?

MWE added:

\documentclass{article}

\begin{document}
    \begin{table}
        \begin{tabular}{|c|l|} \hline
            Item & \multicolumn{1}{c|}{Entries \hfil (length)} \\ \hline
            1 & 1, 2, 3, 4, 5, 6, 7 \hfil (7) \\ \hline
            2 & 1, 2, 3, 4, 5, 6, 7, 8, 9 \hfil (9) \\ \hline
            3 & 1, 2, 3, 4 \hfil (4) \\ \hline
        \end{tabular}
    \end{table}
\end{document}

2 Answers 2

3

Why don't you use 3 columns? Also, you might use the booktabs package: no vertical rules and better vertical spacing between rows. I give an example of both:

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}
    \begin{tabular}[b]{|c|lc|} \hline
        Item & \multicolumn{1}{c}{Entries} & (length) \\ \hline
        1 & 1, 2, 3, 4, 5, 6, 7 & (7) \\ \hline
        2 & 1, 2, 3, 4, 5, 6, 7, 8, 9 & (9) \\ \hline
        3 & 1, 2, 3, 4 & (4) \\ \hline
    \end{tabular}
\end{table}
\mbox{}%\vskip1cm%
\begin{table}[! h]
    \begin{tabular}[b]{@{}clc@{}}
        Item & \multicolumn{1}{c}{Entries} & (length) \\\addlinespace[0.5ex] \toprule
        1 & 1, 2, 3, 4, 5, 6, 7 & (7) \\ \addlinespace
        2 & 1, 2, 3, 4, 5, 6, 7, 8, 9 & (9) \\ \addlinespace
        3 & 1, 2, 3, 4 & (4) \\ \bottomrule
    \end{tabular}
\end{table}

\end{document} 

enter image description here

1

Here is how I would do it:

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
  \begin{tabular}{clc}
   \toprule
    Item & \multicolumn{1}{c}{Entries} & (length) \\
   \midrule
    $1$  & $1,2,3,4,5,6,7$             & $(7)$    \\
    $2$  & $1,2,3,4,5,6,7,8,9$         & $(9)$    \\
    $3$  & $1,2,3,4$                   & $(4)$    \\
   \bottomrule
  \end{tabular}
\end{table}

\end{document}

output

(It's similar to Bernard's last solution, I now see, but with the \toprule above the table and a \midrule just under the text.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .