开发者

how to make values of the table cell to centre in latex?

Please tell me how to make the values in this table to appear in the centre.

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


Here's one way. But it's probably not the "correct" 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}


To have it a bit shorter, you could also do the following:

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

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

Now you have to use \tabularnewline instead of \\ to declare a new line, though. If the width of your columns isn't important, you could also use

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

without any further changes.


The tabularray package makes it easy to configure the horizontal alignment:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{table}[h]
    \begin{center}
        \caption{Mobile IP throughput statistics}
        \begin{tblr}{
          colspec={Q[2.5cm] Q[2.5cm] Q[2.5cm]},
          columns={halign=c},
          vlines,
          hlines
        }
          Speed (km/hr) & Max (packets/sec) & Sample mean (packets/sec) \\
          20  & 261.67 &  209.05\\
          70  & 262.5  &  207.91\\
          80  & 259.58 &  209.03\\ 
          90  & 260.75 &  209.47\\
          100 & 260.33 &  209.3 \\
          120 & 262.42 &  210.4 \\
          160 & 259.08 &  210.29\\                 
        \end{tblr}
        \label{table:table3}
    \end{center}
\end{table}

\end{document}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜