1
我剛開始使用Astropy
以LaTeX格式編寫表格。但是,當我寫下這張表格時,它的工作就是完成這個工作,標準化爲大質量的單位,通常是1e6太陽質量,顯示時沒有科學記數法。如何在Astropy中指定LaTeX輸出格式
一個例子:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def table_write():
from astropy.io import ascii
import astropy.table
import astropy.units as u
#fake data, ~ the same order of magnitude of real ones
Mbh = [1e1, 7e3]
t_final = [13, 12.2]
tab = astropy.table.Table([Mbh, t_final],
names = ['Mbh', 't_final'])
tab['Mbh'].unit = '1e6 Msun'
tab['t_final'].unit = 'Gyr'
ascii.write(tab,
Writer=ascii.Latex,
latexdict=ascii.latex.latexdicts['AA'])
if __name__ == "__main__":
table_write()
輸出是
\begin{table}
\begin{tabular}{cc}
\hline \hline
Mbh & t_final \\
$\mathrm{1000000\,M_{\odot}}$ & $\mathrm{Gyr}$ \\
\hline
10.0 & 13.0 \\
7000.0 & 12.2 \\
\hline
\end{tabular}
\end{table}
這是好的,除了
\ mathrm {百萬\中,M _ {\ ODOT}}
哪sh烏爾德是一個不錯的
\ mathrm {10^{6} \中,M _ {\ ODOT}}
所以,我想格式化單元的一部分。 documentation似乎報告了一種方法來做到這一點,但它絕對不清楚。
這兩個輸出都不是我通過長鏡頭稱之爲「好」的東西。相反,萎縮應該輸出使用LaTeX軟件包的代碼,該軟件包可在LaTeX中自定義。這可能嗎? –
siunitx是否可用,例如,在mathjax中? – Iguananaut