如何使文本位于表格列的中心

如何使文本位于表格列的中心

我必须在我的报告中添加一个表格。请看图片。我如何更改代码,以便每列中的文本适合每个框的中间。如果您看到最后一列的文本位于框的最左侧。请问我如何将其置于中心?

多谢。

\begin{table}[h!]
\centering
\begin{tabular}{|p{2.5cm}|p{2.5cm}|p{6cm}| }
 \hline
 \multicolumn{3}{|c|}{TDOA estimation and sampling frequency} \\
 \hline
 Actual TDOA[PS]&Estimated TDOA[PS]&Sampling frequency[GHz]\\
 \hline
$1-10$&High&High\\
\hline
$1-5$&Medium/High&Low\\
\hline
$2$-$10$&Medium&Low\\
\hline
$20-50$&Medium/Low&Low\\
\hline
$1-10$&Low&Low\\
\hline
$1-30$&Low&Low\\
 \hline
\end{tabular}
\caption{TDOA estimation and sampling frequency using Lagrange interpolation}
\label{table:1}
\end{table}

在此处输入图片描述

答案1

我会在第一列中使用 来@{--}表示范围,由于这不是减法,因此这里不需要数学模式。此外Actualestimated都是 TDOA 估计的两种方法,因此可以将它们归为一个类别,TDOA [ps]

\documentclass{article}
\usepackage{booktabs}
\usepackage[hang,bf,small]{caption}
\begin{document}

\begin{table}[h!]
  \centering
  \caption{TDOA estimation and sampling frequency using Lagrange interpolation}
  \label{table:1}
  \begin{tabular}{r@{--}lcc} \toprule
  \multicolumn{3}{c}{TDOA [ps]} &   \\ \cmidrule(lr){1-3}
  \multicolumn{2}{c}{Actual}    & Estimated     &Sampling frequency [GHz] \\ \midrule
  1&10      &High           &High   \\
  1&5       &Medium/High    &Low    \\
  2&10      &Medium         &Low    \\
  20&50     &Medium/Low     &Low    \\
  1&10      &Low            &Low    \\
  1&30      &Low            &Low    \\\bottomrule
  \end{tabular}
\end{table}

\end{document}

在此处输入图片描述

答案2

我认为您需要p列,而不能简单地用c列替换它们。

使用array包,并>{\centering}在列之前添加p。请注意,\\表格行分隔符现在已替换为\tabularnewline

\documentclass{article}

\usepackage{array}

\begin{document}
\begin{table}[h!]
\centering
\begin{tabular}{|>{\centering}p{2.5cm} |>{\centering}p{2.5cm} |>{\centering}p{6cm}|}
 \hline
 \multicolumn{3}{|c|}{TDOA estimation and sampling frequency} \tabularnewline
 \hline
 Actual TDOA[PS]&Estimated TDOA[PS]&Sampling frequency[GHz]\tabularnewline
 \hline
$1-10$&High&High\tabularnewline
\hline
$1-5$&Medium/High&Low\tabularnewline
\hline
$2$-$10$&Medium&Low\tabularnewline
\hline
$20-50$&Medium/Low&Low\tabularnewline
\hline
$1-10$&Low&Low\tabularnewline
\hline
$1-30$&Low&Low\tabularnewline
 \hline
\end{tabular}
\caption{TDOA estimation and sampling frequency using Lagrange interpolation}
\label{table:1}
\end{table}
\end{document}

输出

在此处输入图片描述

我还擅自更改了您的格式:

  • 用于booktabs规则(\toprule\midrule\bottomrule
  • 表格标题位于表格上方,图形标题位于图形下方
  • 添加了caption包以便更好地间隔和格式化标题。
  • 删除multicolumn表格中看似不必要的元素,标题应该告诉读者该表格的内容。
  • 排版间隔时应number dash number使用短划线--,而不是内联数学环境$$,因为它意味着number minus number

梅威瑟:

\documentclass{article}

\usepackage{array,booktabs}
\usepackage[hang,bf,small]{caption}

\begin{document}
\begin{table}[h!]
\centering
\caption{TDOA estimation and sampling frequency using Lagrange interpolation}
\label{table:1}
\begin{tabular}{>{\centering}p{2.5cm} >{\centering}p{2.5cm} >{\centering}p{6cm}}
 \toprule
 % \multicolumn{3}{c}{TDOA estimation and sampling frequency} \tabularnewline
 % \midrule
 Actual TDOA[PS]&Estimated TDOA[PS]&Sampling frequency[GHz]\tabularnewline
 \midrule
1--10 &High&High\tabularnewline
1--5  &Medium/High&Low\tabularnewline
2--10 &Medium&Low\tabularnewline
20--50&Medium/Low&Low\tabularnewline
1--10 &Low&Low\tabularnewline
1--30 &Low&Low\tabularnewline
 \bottomrule
\end{tabular}
\end{table}
\end{document}

输出

在此处输入图片描述

相关内容