[LaTeX] 在 LaTeX 中对齐表格中的小数点

Intro

在使用 LaTeX 创建表格的时候,我们经常会输入例如1.1012.22等类似的数字。但是不管使用居中对齐、右对齐或者是左对齐,因为数字长短不一,所以小数点处是不对齐的。例如下面两个图:

right align

center align

Solution

使用@{.}。其中小数点.可以换做其他符号。

\begin{table}[t]
    \centering
    \begin{tabular}{l  r@{.}l}
    \toprule
        \textbf{Name}   & \multicolumn{2}{l}{\textbf{Birthday}} \\ \midrule
        Xovee Xu        & 3 & 12 \\
        Tim Cook        & 11& 1  \\
        Michael Jackson & 8 & 29 \\
        Santa Claus     & 12& 25 \\
        Airi Suzuki     & 4 & 12 \\
    \bottomrule
    \end{tabular}
    \caption{Demo}
    \label{tab:demo}
\end{table}

demo

Reference

  1. lockstep, Werner. (Mar 20, 2020). Aligning numbers by decimal points in table columns. Retrieved from https://tex.stackexchange.com/questions/2746/aligning-numbers-by-decimal-points-in-table-columns
发布了40 篇原创文章 · 获赞 84 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/xovee/article/details/104996350