I want to write such a table, enter image description here

but I find that the columns are not strictly centered.

How to modify the code to make it correct?

        & Beijing & Shenzhen\\
        & \begin{tabular}{cc}\midrule Price (\$)&Size\end{tabular}
        & \begin{tabular}{cc}\midrule Price (\$)&Size\end{tabular}\\
    House1 & \begin{tabular}{cc}94.80&  94.8000\end{tabular} &  \begin{tabular}{cc}94.80&  94.80\end{tabular}    \\
    House2 & \begin{tabular}{cc}94.80&  94.80\end{tabular} &  \begin{tabular}{cc}94.80&  94.80\end{tabular}    \\
    House3 & \begin{tabular}{cc}94.80&  94.80\end{tabular}&  \begin{tabular}{cc}94.80&  94.80\end{tabular}  \\
  • 1
    Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem.
    – NBur
    Jun 16 at 14:53
  • Why do you have extra tabulars in the middle of your table?
    – Teepeemm
    Jun 16 at 14:54
  • Do you really need $4$ decimal digits in the third column thi=rd row?
    – Bernard
    Jun 16 at 14:57
  • 1
    And 94.8000 is centered over 94.80. Do you want it centered like that, or do you want the decimal points to line up?
    – Teepeemm
    Jun 16 at 14:58
  • @NBur Sorrt for that, and the problem will be happen again next time. Indeed there is not need to do so, but that is the only way I knew to write such a table. Now I know the right way, as posted by Mico. Thank all of you for kindly help
    – 陈绍伍
    Jun 16 at 16:13

I assume that by "strictly centered", you mean "centered on the decimal markers". If this interpretation is correct, the following solution may be of interest to you. Compared to the code you posted, it uses a single 5-column tabular environment and omits all interior tabular environments. It also (a) employs the S column type to perform alignment on the decimal markers and (b) provides two \cmidrule directives to provide the lines that are shown in the screenshot you posted.

enter image description here

\usepackage{siunitx} % for 'S' column type
    \sisetup{table-format=2.2} % set the default layout
    \begin{tabular}{@{} l S S[table-format=2.4] S S @{}}
    & \multicolumn{2}{c}{Beijing} & \multicolumn{2}{c@{}}{Shenzhen}\\
    \cmidrule(lr){2-3} \cmidrule(l){4-5}
    & {Price (\$)} & {Size} & {Price (\$)} & {Size}\\
    House1 & 94.80 & 94.8000 & 94.80 &  94.80   \\
    House2 & 94.80 & 94.80   & 94.80 &  94.80   \\
    House3 & 94.80 & 94.80   & 94.80 &  94.80   \\

  • Thanks a lot, your table is the exactly what I need, it help a lot
    – 陈绍伍
    Jun 16 at 16:18
  • @陈绍伍 - You're most welcome!
    – Mico
    Jun 16 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.