2

I want to round the number to 2 decimal places. I tried the below code, but it messes with the header.

MWE

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}

\begin{document}

\begin{table}
    \sisetup{round-mode=places}
    \centering
    \begin{tabular}{{|p{1.5cm}|c|p{1.5cm}|p{1.5cm}|p{1.6cm}|p{1.6cm}|}}
        \hline
        Molecule name & \# Structures & Mean $\Delta E$ (kcal/mol) & STD $\Delta E$ (kcal/mol) & Mean RMSD (\si{\angstrom}) & STD RMSD (\si{\angstrom}) \\
        \hline
        Propane & 10  & -5.532722 & 11.871219 & 0.525246 & 0.933334 \\
        \hline
        Pentane & 30  & -9.190216 & 2.529992 & 0.126386 & 0.047781 \\
        \hline
    \end{tabular}
    \caption{somcap}
\end{table}
\end{document}

enter image description here

1
  • Put the header texts between curly brackets {...}
    – CarLaTeX
    Jan 8, 2023 at 8:15

1 Answer 1

4

Like this?

enter image description here

YourS column settings as well table columns specifications are not complete. You need to specify table-format at each S column, move round-precision to \sisetup (for shorter column specifications), and define \multicolumn column header for fourth and fifth columns:

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{siunitx}
\usepackage{makecell}  % new, needed at column headers
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c|}{\makecell{#2}}}


\begin{document}
                
\begin{table}
    \sisetup{round-mode=places,
             round-precision=2,
             table-column-width=3em % for equal 4 and 5 column widths
             }
    \centering
    \begin{tabular}{|p{1.5cm}|c
                    |S[table-format=-1.2]
                    |S[table-format=2.2]
                    |*{2}{S[table-format=1.2]|}
                    } 
        \hline
Molecule name
    & \# Structures
        & \mcc{Mean $\Delta E$\\ (kcal/mol)}
            & \mcc[2]{Mean\\ RMSD (\si{\angstrom})}
                & \mcc{STD\\ RMSD (\si{\angstrom})}     
                \\
        \hline
        Propane & 10  & -5.532722 & 11.871219 & 0.525246 & 0.933334 \\
        \hline
        Pentane & 30  & -9.190216 & 2.529992 & 0.126386 & 0.047781 \\
        \hline
    \end{tabular}
    \caption{somcap}
\end{table}
\end{document}

Addendum:
Meanwhile OP change table design. For new style is needed to add new column header and remove option for two column cell. Since now are changed minimal column widths, it be finne to change it accordingly:

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{siunitx}
\usepackage{array, makecell}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c|}{\makecell{#2}}}


\begin{document}
                
\begin{table}
    \sisetup{round-mode=places,
             round-precision=2,
             table-column-width=4em
             }
    \centering
    \begin{tabular}{|m{1.5cm}|c
                    |S[table-format=-1.2]
                    |S[table-format=2.2]
                    |*{2}{S[table-format=1.2]|}
                    } 
        \hline
Molecule name
    & \# Structures
        & \mcc{Mean $\Delta E$\\ (kcal/mol)}
            & \mcc{STD\\ $\Delta E$ (\si{\angstrom})}
                & \mcc{Mean\\ RMSD (\si{\angstrom})}
                    & \mcc{STD\\ RMSD (\si{\angstrom})}
                \\
    \hline
Propane & 10  & -5.532722 & 11.871219 & 0.525246 & 0.933334 \\
    \hline
Pentane & 30  & -9.190216 & 2.529992 & 0.126386 & 0.047781 \\
    \hline
    \end{tabular}
    \caption{somcap}
\end{table}
\end{document}

enter image description here

6
  • I have edited the question I don't have multi-columns. thnx for the help Jan 8, 2023 at 9:20
  • @WhySoSerious, seriously? This change you can implement in my answer yourself ... it is simple ...
    – Zarko
    Jan 8, 2023 at 9:24
  • @WhySoSerious, see addendum to answer. Now you my consider to upvote it and accept it too (by clicking on check mark at top left side of answer; so far as I see, You not accept any answer from received on your questions).
    – Zarko
    Jan 8, 2023 at 9:33
  • I was trying to understand your answer to adding 1 column. I am new to latex. Jan 8, 2023 at 9:45
  • 1
    @WhySoSerious, the \mcc (abbreviation for multi column centered ) is defined as shorthand for \multicolumn{<number of columns>}{c|}{\makecell{<content>}} . By it are overwritten coS column headers and enable to write multiline text. For definition is used command \NewExpandableDocumentCommand originally defined in xparse package, now integrated in recent versions of LaTeX. How this command works is described in its documentation. It can find it on texdoc.org/serve/xparse/0
    – Zarko
    Jan 8, 2023 at 12:31

You must log in to answer this question.

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