1

I have this table and I want to center columns 2, 3 and 4.

\begin{table}[h!]
    \centering
    \caption{Number of sub-indicators}
    \begin{tabular}{|l| p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
        \toprule
        \multicolumn{1}{|r|}{\textbf{Group indicators}} & \multicolumn{1}{r|}{\textbf{QSC}} & \multicolumn{1}{r|}{\textbf{SCAD15}} & \multicolumn{1}{r|}{\textbf{SCAD5}} & \multicolumn{1}{r|}{\textbf{AVE}} \\
        \midrule
        Dissimilarity & 0     &       &       &  \\
        \midrule
        Enrollment & 81    & 70    & 70    & 6.2 \\
        \midrule
        Attendance & 99    & 1     & 1     & 0 \\
        \midrule
        Entry & 8     & 8     & 8     & 2.5 \\
        \midrule
        School life expectancy & 4     & 4     & 4     & 13.3 \\
        \midrule
        Graduation & 4     & 4     & 4     & 4 \\
        \midrule
        Graduates & 62    & 62    & 62    & 2.4 \\
        \midrule
        Mobility & 10    & 7     & 6     & 7.1 \\
        \midrule
        Attainment & 4     & 3     & 0     & 0.75 \\
        \midrule
        Teachers staff & 10    & 7     & 7     & 9 \\
        \midrule
        Teacher-pupil ratio & 1     & 1     & 1     & 14 \\
        \midrule
        Expenditure & 11    & 0     & 0     & 3 \\
        \midrule
        Government funding & 6     & 6     & 0     & 2 \\
        \midrule
        School age population & 3     & 3     & 3     & 14 \\ \hline
        \multicolumn{5}{|l|}{\textbf{QSC: Quantity of sub-categories (number)}} \\
        \multicolumn{5}{|l|}{\textbf{SCAD15: Sub-categories with  data in at least one year in the last 15 years}} \\
        \multicolumn{5}{|l|}{\textbf{in number}} \\
        \multicolumn{5}{|l|}{\textbf{SCAD5: Sub-categories with  data in at least one year in the last five years}} \\
        \multicolumn{5}{|l|}{\textbf{in number}} \\
        \multicolumn{5}{|l|}{\textbf{AVE: Average of available data per indicators in the last 15 years (number)}} \\
        \bottomrule
    \end{tabular}%
    \label{tab:numb-subindicator}%
\end{table}%
6
  • 2
    Why do you want to use p type columns for columns only containing numbers? Why not simply use c type columns? If you insist on 2cm wide columns, you might want to ad the array package to your pramble and give W{c}{2cm} a try. Personally, I would use S type columns from siunitxfor all the columns that contain numbers. With them you can center the numbers while also aligning their decimal separators.
    – leandriis
    Apr 6, 2020 at 6:40
  • Unrelated to the alignment but please keep in mind that horizontal lines from the booktabs package are not intended to be used in combination with vertical lines. (See all the small geps around the intersections.) I suggest you remove all vertical lines.
    – leandriis
    Apr 6, 2020 at 6:43
  • In addition to leandriss' comment on the vertical lines, I'd also remove most of the \midrule's a grip like structure like this does not help with the readability of the table.
    – daleif
    Apr 6, 2020 at 6:46
  • I use p because when I use c option the last column is too wide respect to others Apr 6, 2020 at 7:06
  • @AndreyVinajera: Take a look at the threeparttable package then. With it you can add tablenotes to your table. The width of these notes automatically adapts to the overall width of the table. I have used that package in my answer.
    – leandriis
    Apr 6, 2020 at 7:17

2 Answers 2

1

Here is my suggestion using siunitx for the improved alignment of numbers in table columns as well as threeparttable for the tablenotes. As mentioned in the comments, I have also removed all vertical lines and most of teh horizontal ones. Additionally, I have also removed the \textbf commands, especially the ones for teh table notes.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{threeparttable}
\begin{document}
\begin{table}
\begin{threeparttable}
    \centering
    \caption{Number of sub-indicators}
    \begin{tabular}{l *{3}{S[table-format=2]} S[table-format=2.2]}
        \toprule
        Group indicators & {QSC} & {SCAD15} & {SCAD5} & {AVE} \\
        \midrule
        Dissimilarity & 0     &       &       &  \\
        Enrollment & 81    & 70    & 70    & 6.2 \\
        Attendance & 99    & 1     & 1     & 0 \\
        Entry & 8     & 8     & 8     & 2.5 \\
        School life expectancy & 4     & 4     & 4     & 13.3 \\
        Graduation & 4     & 4     & 4     & 4 \\
        Graduates & 62    & 62    & 62    & 2.4 \\
        Mobility & 10    & 7     & 6     & 7.1 \\
        Attainment & 4     & 3     & 0     & 0.75 \\
        Teachers staff & 10    & 7     & 7     & 9 \\
        Teacher-pupil ratio & 1     & 1     & 1     & 14 \\
        Expenditure & 11    & 0     & 0     & 3 \\
        Government funding & 6     & 6     & 0     & 2 \\
        School age population & 3     & 3     & 3     & 14 \\ 
        \bottomrule
    \end{tabular}%
    \begin{tablenotes}[online]\small
          \item[QSC:] Quantity of sub-categories (number) 
          \item[SCAD15:] Sub-categories with  data in at least one year in the last 15 years (number) 
          \item[SCAD5:] Sub-categories with  data in at least one year in the last five years (number)
          \item[AVE:] Average of available data per indicators in the last 15 years (number)
    \end{tablenotes}
    \label{tab:numb-subindicator}%
\end{threeparttable}
\end{table}%
\end{document}
2
  • How I can do to give more width to the table for note don't take too many rows and make a line at the end of notes Apr 6, 2020 at 7:38
  • How much is "more width"? Do you want to prevent linebreaks of the individual descriptions alltogehter? Ho wide should the horizontal line below the notes be? Should the wider notes extend only to the right or to the left and right? Should the table still be centeres in the textwidth? Please clarify the desired output.
    – leandriis
    Apr 6, 2020 at 8:22
1

I propose this variant layout, with numeric columns of equal width (hence a wider table), and some coloured rules:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[svgnames, table]{xcolor}
\usepackage{threeparttable}

\begin{document}

\begin{table}
\centering
\newlength{\Swd}\settowidth{\Swd}{SCAD15}
\setlength{\extrarowheight}{2pt}
\sisetup{table-column-width=\Swd, table-number-alignment=center}
\arrayrulecolor{Gainsboro!60!Lavender}
\begin{threeparttable}
\caption{Number of sub-indicators}
\begin{tabular}{l !{\color{Gainsboro!60!Lavender}\vrule width 3pt}*{3}{S} S}
    \toprule[0.4ex]
    Group indicators & {QSC} & {SCAD15} & {SCAD5} & {AVE} \\
    \midrule
    Dissimilarity & 0 & & & \\
    Enrollment & 81 & 70 & 70 & 6.2 \\
    Attendance & 99 & 1 & 1 & 0 \\
    Entry & 8 & 8 & 8 & 2.5 \\
    School life expectancy & 4 & 4 & 4 & 13.3 \\
    Graduation & 4 & 4 & 4 & 4 \\
    Graduates & 62 & 62 & 62 & 2.4 \\
    Mobility & 10 & 7 & 6 & 7.1 \\
    Attainment & 4 & 3 & 0 & 0.75 \\
    Teachers staff & 10 & 7 & 7 & 9 \\
    Teacher-pupil ratio & 1 & 1 & 1 & 14 \\
    Expenditure & 11 & 0 & 0 & 3 \\
    Government funding & 6 & 6 & 0 & 2 \\
    School age population & 3 & 3 & 3 & 14 \\
    \bottomrule[0.4ex]
\end{tabular}%
\begin{tablenotes}[online]\small\smallskip
      \item[QSC:] Quantity of sub-categories (number)
      \item[SCAD15:] Sub-categories with data in at least one year in the last 15 years (number)
      \item[SCAD5:] Sub-categories with data in at least one year in the last five years (number)
      \item[AVE:] Average of available data per indicators in the last 15 years (number)
\end{tablenotes}
\label{tab:numb-subindicator}%
\end{threeparttable}
\end{table}%

\end{document} 

enter image description here

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.