帶有 siunitx 的表 - 在精確度模式下對齊

帶有 siunitx 的表 - 在精確度模式下對齊

在此輸入影像描述

在一個測試在製作桌子時,我使用很酷的包siunitx來對逗號後的值進行一些定義的精度,並將這些值對齊在中間一列,但不幸的是,它正在對文字進行一些對齊Val 2,但$\beta$保持不變。2即使先前的文字像 2.00 一樣,該數字是否被視為 siunitx 的值?或者我是否必須為第一行創建一個單獨的表(Val 1 ... Val 3) - 不相信...

這是我的程式碼:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{frcursive}
\usepackage{amsmath}


% le package qui pemet de définir des unités et leur affichage
\usepackage{siunitx} % Required : alignement des valeurs etc.
\sisetup{
    round-mode          = places, % Rounds numbers
    round-precision     = 2, % to 2 places
}

\begin{document}

%exemples de tableau
\noindent\begin{cursive}Des tableaux:\end{cursive}
\begin{table}[h!]
    \begin{center}

    \label{tab:table1}
        
        \begin{tabular}{l|c|r} % Alignements: left, center, right
            \textbf{Val 1} & \textbf{Val 2} & \textbf{Val 3}\\
            $\alpha$ & $\beta$ & $\gamma$ \\
            \hline
            1 & 1110.1 & a\\
            2 & 10.1 & b\\
            3 & 23.113231 & c\\
        \end{tabular}
    \caption{Valeurs basiques}

\vspace{1cm}    

    \label{tab:table2}
    
    \begin{tabular}{l|S|r} % c devient S ==> unitsx
        \textbf{Val 1} & \textbf{Val 2} & \textbf{Val 3}\\
        $\alpha$ & $\beta$ & $\gamma$ \\
        \hline
        1 & 1110.1 & a\\
        2 & 10.1 & b\\
        3 & 23.113231 & c\\
    \end{tabular}
  \caption{Valeurs alignées et arrondies}
  
    \end{center}
  \end{table}


\end{document}

答案1

  • 您需要table-format根據您的情況定義要在表格中顯示的小數位數table-format=4.2
  • 列標題不是數字,應在文字中居中,應括在花括號中
  • 表格標籤必須位於標題之後
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{frcursive}
\usepackage{amsmath}
% le package qui pemet de définir des unités et leur affichage
\usepackage{siunitx} % Required : alignement des valeurs etc.
\sisetup{   % this is now globally set, you ma consider to move it inside table
    round-mode      = places, % Rounds numbers
    round-precision = 2, % to 2 places
}

\begin{document}
%exemples de tableau
\noindent\begin{cursive}Des tableaux:\end{cursive}
    \begin{table}[h!]
\centering
    \begin{tabular}{l|c|r} % Alignements: left, center, right
\textbf{Val 1} & \textbf{Val 2} & \textbf{Val 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
    \hline
1 & 1110.1      & a\\
2 & 10.1        & b\\
3 & 23.113231   & c\\
    \hline
    \end{tabular}
\caption{Valeurs basiques}
\label{tab:table1}
   
\vspace{2\baselineskip}
    \begin{tabular}{l|S[table-format=4.2]|r}             % <---
\textbf{Val 1}  & {\textbf{Val 2}} & \textbf{Val 3}  \\  % <---
$\alpha$}       & {$\beta$}        & $\gamma$        \\  % <---
    \hline
1 & 1110.1      & a\\
2 & 10.1        & b\\
3 & 23.113231   & c\\
    \hline
    \end{tabular}
\caption{Valeurs alignées et arrondies}
\label{tab:table2}
  \end{table}
\end{document}

在此輸入影像描述

相關內容