How to make table cell values ​​centered in latex?

Tell us how to make the values ​​in this table displayed in the center.

\begin{table}[h]
    \begin{center}
\caption{Mobile IP throughput statistics}
        \begin{tabular}{ | p{2.5cm} | p{2.5cm} | p{2.5cm} | }
            \hline Speed (km/hr) & Max (packets/sec)  & Sample mean (packets/sec) \\
            \hline 20 & 261.67 &  209.05\\
                           \hline 70 & 262.5 &  207.91\\
                           \hline 80 & 259.58 &  209.03\\ 
                           \hline 90 & 260.75 &  209.47\\
                           \hline 100 & 260.33 &  209.3\\
                            \hline 120 & 262.42 &  210.4\\
                            \hline 160 & 259.08 &  210.29\\                                 
            \hline
        \end{tabular}

        \label{table:table3}
    \end{center}
\end{table}

thank

+3
source share
2 answers

Here is one way. But this is probably not the “right” way:

\begin{tabular}{ | p{2.5cm} | p{2.5cm} | p{2.5cm} | }
  \hline \centering  Speed (km/hr) & Max (packets/sec) & Sample mean (packets/sec) \\
  \hline \centering  20 & \centering 261.67 & 209.05 \\
  \hline \centering  70 & \centering 262.5  & 207.91 \\
  \hline \centering  80 & \centering 259.58 & 209.03 \\ 
  \hline \centering  90 & \centering 260.75 & 209.47 \\
  \hline \centering 100 & \centering 260.33 & 209.3  \\
  \hline \centering 120 & \centering 262.42 & 210.4  \\
  \hline \centering 160 & \centering 259.08 & 210.29 \\                                 
  \hline
\end{tabular}
+4
source

To make this a little shorter, you can also do the following:

Put \usepackage{array}in your head and in the expression \begin{tabular}write the following:

\begin{tabular}{ | >{\centering}p{2.5cm} | >{\centering}p{2.5cm} | >{\centering}p{2.5cm} | }

Now you need to use \tabularnewlineinstead \\to declare a new line. If the column width is not important, you can also use

\begin{tabular}{ |c|c|c| }

without any further changes.

+4
source

All Articles