Trevor
I have the following code (a minimal working example):


\documentclass{article}
\begin{document}

\begin{tabular}{ l c c }
& \textbf{a} & \textbf{b} \\
\textbf{x} & 600 millisec & 20 sec \\
\textbf{y} & 10 sec & 300 sec \\
\textbf{z} & 2 sec & 4 sec \\
\end{tabular}

\end{document}


which produces this table:

![output](/image?hash=be1b05a8274c0b93320aa41c302b4a1ee4bb81cee238c3ff928b29302826027f)

However, I want to align the entries in each column so that all "sec" and "millisec" are aligned. So I want to produce something that looks like this:

How do I accomplish this?

*Note*: This question is solely about alignment, not scientific presentation. The "sec" and "millisec" are just examples, and can be replaced with any other words or phrases.

samcarter
The usual advice in presenting quantitative information is to keep the information/ink ratio as good as possible. Amongst other things, this means that repetitive information should be avoided if possible.

In case of your table, you could thus place the unit in the column header and avoid both the repetition of the same information and your alignment problem -- two birds, one stone.


\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}
\DeclareSIUnit{\second}{\text{sec}}

\begin{document}

\begin{tabular}{
@{}
l
S[table-format=2.1]
S[table-format=3.0]
@{}
}
\toprule
& {a (in \unit{\second})} & {b (in \unit{\second})} \\
\midrule
x & 0.6 & 20 \\
y & 10 & 300\\
z & 2 & 4\\
\bottomrule
\end{tabular}

\end{document}

![Screenshot 2021-08-19 at 10.39.45.png](/image?hash=cb9da556a6f1fa60980f9abb9b1ea3aeee2a2b0ccec72d553a39da8aacd23865)
निरंजन
I am sure this might not be the best way to do this, there must be packages to automate this kinda mechanism, but it wasn't too difficult to do it manually also.

@{\hspace{0.1cm}} modifies the space in two columns. You can in/de-crease it.

I have added package booktabs for nice lines in the table. You are of course free to remove it (and remove the \top-/\mid-/\bottom-rules) to make it line-free.

I have defined three new column types which are R, L and C. These can take width arguments now. The only possible solution I could think of to make the header centered when its child columns are of uneven widths was to increase their widths significantly and make them of equal widths by brute force.


\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}
\begin{tabular}{%
l%
R{0.2\linewidth}@{\hspace{0.1cm}}%
L{0.2\linewidth}%
R{0.2\linewidth}@{\hspace{0.1cm}}%
L{0.2\linewidth}%
}
\toprule
& \multicolumn{2}{C{0.4\linewidth}}{\textbf{one long long title}}
& \multicolumn{2}{C{0.4\linewidth}}{%
\textbf{another very long and absolutely non-sense title.}%
}\\
\midrule
\textbf{x} & 600 & millisec &  20 & sec\\
\textbf{y} & 10  & sec      & 300 & sec\\
\textbf{z} & 2   & sec      &   4 & sec\\
\bottomrule
\end{tabular}
\end{document}


![Screenshot_2021-08-20_10-26-07.png](/image?hash=d39a322d33f8e8465e6298f639869d6a610cfe9bccb63f2434c03ba0b7993167)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.