2

How I can center column with specifying width in table? For example, in the next code:

\begin{table} [H]  \footnotesize

\setlength{\tabcolsep}{5.5pt}
\centering
\setlength{\arrayrulewidth}{1\arrayrulewidth}
\renewcommand{\arraystretch}{1.3}
\caption{Massas e percentuais das frações separadas pelo ES.}
\vspace{-0.3cm}

    \begin{tabular}{p{2cm}p{2cm}p{2cm}p{2cm}p{2cm}p{2cm}}

    \hline 
    Velocidades separação (m/s) & Quantidade de partículas & Fração mássica ($g$) & \% massa & Partícula de maior comp. ($mm$) & Partícula de menor comp. ($mm$) \\ 

\hline 
0,504 & 8200 & 7,6 & 15\% & 0,5 \pm 0,004 & 0,28 \pm 0,003\\
0,710 & 2040 & 5,0 & 10\% & 2,6 \pm 0,1 & 0,90 \pm 0,06 \\
1,062 & 450 & 9,0 & 18\% & 6,2 \pm 0,5 & 1,75 \pm 0,21 \\
1,578 & 432 & 10,8 & 21\% & 7,0 \pm 0,4 & 1,78 \pm 0,64 \\
1,930 & 227 & 5,4 & 11\% & 11,7 \pm 1,1 & 2,98 \pm 0,37 \\
2,277 & 149 & 3,1 & 6\% & 14,5 \pm 1,5 & 4,05 \pm 0,51 \\
$>$ 2,277 & 98 & 9,8 & 19\% & 17,2 \pm 2,2 & 4,15 \pm 0,63 \\

\hline 
\end{tabular} 
%\begin{tablenotes}
%  \item[]{{nd: Não detectado}}
%\end{tablenotes}
%\end{threeparttable}
\end{table}
  • >{\centering\arraybackslash}p{2cm} should do what you are searching for. – epR8GaYuh Jul 16 '18 at 19:10
  • Related: How to center column values in a table? – leandriis Jul 16 '18 at 19:11
  • i would use S columns and their syntax defined in siunitx. and please extend your code snippet to complete small document beginning with \documentclass{...} and ending with \end{document}. welcome to tex.se! – Zarko Jul 16 '18 at 19:17
  • 1
    Welcome to TeX.SE! Off-topic: What are you trying to achieve with \setlength{\arrayrulewidth}{1\arrayrulewidth}? – Mico Jul 16 '18 at 19:18
  • By "centering", do you actually mean how to make the table fit inside the available width of the text block? – Mico Jul 16 '18 at 19:21
2

I think there's an overriding issue with your table: it's wider than the textblock. (Well, unless your textblock is unusually wide -- something you haven't told us much so far.)

I'd like to suggest that you switch to a tabularx environment and a centered version of that package's X column type for all 6 columns.

Oh, I don't think it's typographically correct to typeset scientific units in math mode; use upright roman letters instead.

enter image description here

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\begin{document}
\begin{table}[ht!]
\small % not necessary to employ "\footnotesize"

%%\renewcommand{\arraystretch}{1.3} % do you really need this?

\caption{Massas e percentuais das frações separadas pelo ES.}
\begin{tabularx}{\textwidth}{@{} *{6}{C} @{}}
\toprule
Velocidades separação (m/s) & Quantidade de partículas & Fração mássica\newline (g) & \% massa & Partícula de maior comp. (mm) & Partícula de menor comp. (mm) \\ 
\midrule    
0,504 & 8200 & 7,6 & 15\% & 0,5$\pm$0,004 &0,28$\pm$0,003\\
0,710 & 2040 & 5,0 & 10\% & 2,6$\pm$0,1 & 0,90$\pm$0,06  \\
1,062 & 450 & 9,0 & 18\% & 6,2$\pm$0,5 & 1,75$\pm$0,21   \\
1,578 & 432 & 10,8 & 21\% & 7,0$\pm$0,4 & 1,78$\pm$0,64  \\
1,930 & 227 & 5,4 & 11\% & 11,7$\pm$1,1 & 2,98$\pm$0,37  \\
2,277 & 149 & 3,1 & 6\% & 14,5$\pm$1,5 & 4,05$\pm$0,51   \\
$>$2,277 & 98 & 9,8 & 19\% & 17,2$\pm$2,2 & 4,15$\pm$0,63\\
\bottomrule
\end{tabularx} 
\end{table}
\end{document}
1

a combination of leandriis and Mico answers :-) :

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs, tabularx}
\newcommand\mcx[1]{\multicolumn{1}{>{\centering\arraybackslash}X}{\footnotesize#1}}

\begin{document}
    \begin{table}
    \sisetup{output-decimal-marker = {,}}
    \setlength\tabcolsep{3.5pt}
\caption{Massas e percentuais das frações separadas pelo ES.}
\label{ua}
\begin{tabularx}{\linewidth}{@{}
                S[input-symbols = {>},table-format=>2.3]
                S[table-format=4]
                S[table-format=2.1]
                S[table-format=2]
                S[table-format=2.2,separate-uncertainty=true,table-figures-uncertainty=1]
                S[table-format=1.3,separate-uncertainty=true,table-figures-uncertainty=1]
                            @{}}
    \toprule
\mcx{Velocidades separação (m/s)}
    &   \mcx{Quantidade de partículas}
        &   \mcx{Fração mássica ($g$)}
            &   \mcx{\% massa}
                &   \mcx{Partícula  de maior comp. (mm)}
                    &   \mcx{Partícula de menor comp. (mm)} \\
    \midrule
0,504   & 8200  & 7,6   & 15    & 0,5 \pm 0,004 & 0,28 \pm 0,003\\
0,710   & 2040  & 5,0   & 10    & 2,6 \pm 0,1   & 0,90 \pm 0,06 \\
1,062   & 450   & 9,0   & 18    & 6,2 \pm 0,5   & 1,75 \pm 0,21 \\
1,578   & 432   & 10,8  & 21    & 7,0 \pm 0,4   & 1,78 \pm 0,64 \\
1,930   & 227   & 5,4   & 11    & 11,7 \pm 1,1  & 2,98 \pm 0,37 \\
2,277   & 149   & 3,1   & 6     & 14,5 \pm 1,5  & 4,05 \pm 0,51 \\
>2,277  & 98    & 9,8   & 19    & 17,2 \pm 2,2  & 4,15 \pm 0,63 \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

enter image description here

1

With a combination of siunitx, booktabs and makecell one can achieve the following table. As suggested by Mico, I have replaced the units in math mode by siunitx's units.

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{booktabs}
\begin{document}

\begin{table} 
\sisetup{output-decimal-marker = {,}}

\centering
\caption{Massas e percentuais das frações separadas pelo ES.}
\label{ua}

\begin{tabular}{S[input-symbols = {>},table-format=>2.3]
                S[table-format=4]
                S[table-format=2.1]
                S[table-format=2]
                S[table-format=2.2,separate-uncertainty=true,table-figures-uncertainty=1]
                S[table-format=1.3,separate-uncertainty=true,table-figures-uncertainty=1]}

\toprule 
{\makecell[tc]{Velocidades \\ separação \\ (\si[per-mode=symbol]{\meter\per\second})}} & {\makecell[tc]{Quantidade \\ de partículas}} & {\makecell[tc]{Fração \\ mássica \\ (\si{\gram})}} & {\% massa} & {\makecell[tc]{Partícula  de \\ maior comp. \\ (\si{\milli\meter})}} & {\makecell[tc]{Partícula de \\ menor comp. \\ (\si{\milli\meter})}} 
\\ 
\midrule 
0,504 & 8200 & 7,6 & 15 & 0,5 \pm 0,004 & 0,28 \pm 0,003\\
0,710 & 2040 & 5,0 & 10 & 2,6 \pm 0,1 & 0,90 \pm 0,06 \\
1,062 & 450 & 9,0 & 18 & 6,2 \pm 0,5 & 1,75 \pm 0,21 \\
1,578 & 432 & 10,8 & 21 & 7,0 \pm 0,4 & 1,78 \pm 0,64 \\
1,930 & 227 & 5,4 & 11 & 11,7 \pm 1,1 & 2,98 \pm 0,37 \\
2,277 & 149 & 3,1 & 6 & 14,5 \pm 1,5 & 4,05 \pm 0,51 \\
>2,277 & 98 & 9,8 & 19 & 17,2 \pm 2,2 & 4,15 \pm 0,63 \\

\bottomrule 
\end{tabular} 
\end{table}

\end{document}
  • I don't think it's good (typographic) praxis to typeset scientific units -- cf. mm and g -- in math mode. Since you're showing how to use the siunitx package, may write \si{g}, \si{\milli\meter}, and \si{\meter\per\second}? – Mico Jul 16 '18 at 19:41

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.