0

i have to add a table in my report. See the picture .How I can change the code so that text in each columns fits in the middle of each box. If you see the last column the text in on extreme left side of the box.How I can make it in center please?

Thanks a lot.

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

enter image description here

2 Answers 2

2

I would use a @{--} for the ranges in the first column and since this is not a subtraction, there is no need for math mode here. Also Actual and estimated are both two methods of TDOA estimation, so these can be grouped under one head, 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}

enter image description here

1
  • +1 for the @{--}. Neat!
    – Holene
    Commented Mar 11, 2016 at 11:06
1

I assume that you need the p columns and can't simply replace them with c columns.

Use the array package, and add >{\centering} prior to your p columns. Take notice that the \\ table row separator is now replaced with \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}

Which outputs

enter image description here

I also took the liberty to change your formatting a bit:

  • Use booktabs for the rules (\toprule, \midrule and \bottomrule)
  • Table captions go above the table, figure captions go below the figure
  • Added the caption package for better spacing and formatting of the caption.
  • Removed the multicolumn as it seems as an unnecessary element in your table, your caption should tell the reader what the table is all about.
  • When typesetting intervals as number dash number you should use the en dash --, and not the inline math environment $$, as it means number minus number.

MWE:

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

which outputs

enter image description here

2
  • 2
    If you use >{\centering\arraybackslash}, you still can use `\\` as a row separator.
    – Bernard
    Commented Mar 11, 2016 at 10:10
  • @Bernard Nice, missed out on that one!
    – Holene
    Commented Mar 11, 2016 at 10:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .