0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

tblr環境でsiunitxを用いて小数点揃えされた表組を行うときのエラーを解決する(tblr環境で小数点揃えする方法)

Posted at

要約

tblr環境でsiunitxを用いた小数点揃えされた表組をしたとき,見出しを2段以上にするとエラーが出る.
そのときはrow{1} = {guard}を入れるとうまくいく.

環境

TeX Live 2024

背景(tblr環境で小数点揃えする方法)

tblr環境を用いて表組を行っている状態で,次のような数値が小数点で揃えられた表を作りたい.

image.png

そのためには,siunitx\UseTblrLibrary{siunitx}としてtblrに読み込ませてから,

\begin{tblr}{
  colspec = {S[table-format=3.1]S[table-format=3.2]},
}

などとして,S columnを用いることで小数点揃えを行うことができる1

課題

次のように記述するとエラーが発生する.

\begin{table}[!htbp]
  \centering
  \begin{tblr}{
    hlines, vlines,
    colspec = {S[table-format=3.1]S[table-format=3.2]},
    rows = {halign = c},
  }
  {Header 1 \\ X [unit]} & {Header 2 \\ Y [unit]}\\
  0 & 5.12 \\
  0.3 & 600 \\
  \end{tblr}
\end{table}

エラーが発生する場合は,冒頭の環境において表のヘッダを2段以上にしたとき(正確には{}を見出しの各列全てにおいて用いたとき)である.たぶん.

解決法

Note that you need to use one pairs of curly braces to guard non-numeric cells. But it is cumber some to enclose each cell with braces. From version 2022B a new key guard is provided for cells and rows. With guard key the previous example can be largely simplified.2

とパッケージドキュメントにあるように,guardを見出し行に適用すればよい.

\begin{table}[!htbp]
  \centering
  \begin{tblr}{
    hlines, vlines,
    colspec = {S[table-format=3.1]S[table-format=3.2]},
    rows = {halign = c},
+   row{1} = {guard},
  }
  {Header 1 \\ X [unit]} & {Header 2 \\ Y [unit]}\\
  0 & 5.12 \\
  0.3 & 600 \\
  \end{tblr}
\end{table}

ちなみに,エラーの再現過程で見出しのうち1つしか2段じゃないときはguard抜きでエラー出なかったので,もしやバグ?とも思った.

よいtabularrayライフを.

  1. https://ctan.org/pkg/tabularray Package documentation p.53 5.9

  2. 同上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?