# Table value alignment

I have a table that looks like this.

I generate it using:

\begin{table*}
\centering
\caption{ The parameters obtained from the fit for the real-space correlation function \xir{} on the sample with $zcosmo$ and the recovered deprojected correlation function $\xi_{dep}(r)$ for the mock photometric samples}
\label{tab:table2}
\begin{tabular}{*{5}{c}}
\hline
\multicolumn{1}{|p{2cm}|}{\centering Redshift uncertainty \\ $\left(\frac{\Delta z}{1+zcosmo}\right)$}
& \multicolumn{1}{|p{2cm}|}{\centering $r_{0}$ \\ $(h^{-1}Mpc)$}
& \multicolumn{1}{|p{2cm}|}{\centering $\gamma$} &
Mass & Fit range \\
\hline
$zcosmo$ & 30.07$\pm$0.66 & 1.8(\textit{fixed}) & $M_{200}>log_{10}(13.7)$ \\ [1ex]
& 40.16$\pm$4.36 & 1.50$\pm$0.09 & $M_{200}>log_{10}(13.7)$ & 5-50 Mpc \\ [1ex]
0.001 & 32.81$\pm$0.80 & 1.8(\textit{fixed}) & $M_{200}>log_{10}(13.7)$ \\ [1ex]
& 36.98$\pm$5.93 & 1.67$\pm$0.15 & $M_{200}>log_{10}(13.7)$ & 5-50 Mpc \\ [1ex]
\end{tabular}
\end{table*}


As you can see, the value in the last column (5-50 Mpc) is aligned with the second row. I want it centred in between the two rows.

• How is the \xir macro defined? – Mico Jun 24 '15 at 13:55
• \def\xir{$\xi(r)$} – Srivatsan Jun 24 '15 at 13:59

You could use the \multirow macro (from the multirow package).

I would also use the rule-drawing macros of the booktabs package, and I'd lose all vertical bars.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,multirow,booktabs,caption}
\newcommand\zcosmo{\textit{zcosmo}}
\begin{document}
\begin{table*}
\centering
\caption{The parameters obtained from the fit for the real-space
correlation function $\xi(r)$ on the sample with $\zcosmo$ and the
recovered deprojected correlation function $\xi_{\textit{dep}}(r)$ for
the mock photometric samples}
\label{tab:table2}
\begin{tabular}{*{5}{c}}
\toprule
\multicolumn{1}{p{2cm}}{\centering Redshift uncertainty \\ $\bigl(\frac{\Delta z}{1+\zcosmo}\bigr)$}
& \multicolumn{1}{p{2cm}}{\centering $r_{0}$ \\ $(h^{-1}Mpc)$}
& \multicolumn{1}{p{2cm}}{\centering $\gamma$} &
Mass & Fit range \\
\midrule
$\zcosmo$ & 30.07$\pm$0.66 & 1.8\ (\textit{fixed}) & $M_{200}>\log_{10}(13.7)$
& \multirow{2}{*}{5--50 Mpc}\\ [1ex]
& 40.16$\pm$4.36 & 1.50$\pm$0.09 & $M_{200}>\log_{10}(13.7)$ &  \\ [1ex]
0.001     & 32.81$\pm$0.80 & 1.8\ (\textit{fixed}) & $M_{200}>\log_{10}(13.7)$
& \multirow{2}{*}{5--50 Mpc}\\ [1ex]
& 36.98$\pm$5.93 & 1.67$\pm$0.15 & $M_{200}>\log_{10}(13.7)$ & \\
\end{tabular}
\end{table*}

\end{document}

• can you elucidate a bit more on the rule-drawing macros of the booktabs package? What are the vertical bars you are talking about – Srivatsan Jun 24 '15 at 14:11
• @ThePredator - The main rule-drawing macros of the booktabs package are \toprule, \midrule, \bottomrule, and \cmidrule. The vertical bars are the ones that get inserted by column specifications such as |p{2cm}| -- they're in the code you provided, though not in the screenshot you posted. – Mico Jun 24 '15 at 14:18
• The "5--50 Mpc" can be moved with the help of package multirow, see the answer of Mico.

• Units can be set with package siunitx. Especially, they are usually not set in italics. Unit "pc" for parsec is not predefined, but it is easy to add a definition:

\DeclareSIUnit{\parsec}{pc}

• Package siunitx also supports table columns with alignment on the decimal dot. As example, columns 2 and 3 are formatted this way. The text "(fixed)" instead of the uncertainty is not supported, thus I have put it from the right via \rlap{(\textit{fixed})}.

• The math functions like log are usually set upright. The example uses macro \log.

• The headers with multiple lines are set as inner tabulars. This avoids the explicit setting of a width and narrower columns.

• As in Mico's example, the vertical lines are removed and the more professional horizontal lines of package booktabs are used.

• The four data entries seem to be two groups, thus I have separated them via \addlinespace.

Full example:

\documentclass{article}

\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{multirow}
\usepackage{siunitx}
\DeclareSIUnit{\parsec}{pc}
\sisetup{
range-units=single,
range-phrase=--,
}
\newcommand*{\xir}{\ensuremath{\xi(r)}}

\begin{document}
\begin{table*}
\centering
\caption{ The parameters obtained from the fit for the real-space
correlation function \xir{} on the sample with $\mathit{zcosmo}$ and the recovered
deprojected correlation function $\xi_{\text{dep}}(r)$ for the mock
photometric samples}
\label{tab:table2}
\def\fixed{\llap{(\textit{fixed})}}
\begin{tabular}{
c
S[table-format=2.2(2), separate-uncertainty]
S[table-format=1.2(2), separate-uncertainty]
cc
}
\toprule
\begin{tabular}[t]{@{}c@{}}
Redshift\\
uncertainty\\
$\left(\frac{\Delta z}{1+zcosmo}\right)$
\end{tabular}
& {\begin{tabular}[t]{@{}c@{}}
$r_{0}$ \\
(\si{\per\hour\mega\parsec})
\end{tabular}}
& \multicolumn{1}{p{2cm}}{\centering $\gamma$} &
Mass & Fit range \\
\midrule
$\mathit{zcosmo}$ & 30.07+-0.66 & 1.8\fixed & $M_{200}>\log_{10}(13.7)$ &
\multirow{2}{*}{\SIrange{5}{50}{\mega\parsec}}\\
& 40.16+-4.36 & 1.50+-0.09 & $M_{200}>\log_{10}(13.7)$ \\
0.001 & 32.81+-0.80 & 1.8\fixed & $M_{200}>\log_{10}(13.7)$ &
& 36.98+-5.93 & 1.67+-0.15 & $M_{200}>\log_{10}(13.7)$ \\

• +1 for letting me know of the siunitx package!! – Srivatsan Jun 24 '15 at 14:32