可以导出到LaTeX的格式非常好的表
tabletexifier的Python项目详细描述
项目目标
提供一个简单的界面来创建表,这些表不仅在终端中打印得很好,而且可以 也很容易导出到乳胶代码。它还希望能够轻松地创建多个科学期刊所需格式的表格。在
如何安装
pip install tabletexifier
如何使用
^{pr2}$通过打印表格,我们已经
>>> print(x)
--------------------------
| Name | b | c | d | e |
+--------+---+---+---+---+
| first | 1 | 4 | 6 | 7 |
+--------+---+---+---+---+
| second | 1 | 4 | 6 | 7 |
--------------------------
它可以通过
>>> print(x.build_latex())
\begin{table}
\caption{\label{Tab:}}
\begin{tabular}{|l|l|l|l|l|}
\hline Name & b & c & d & e \\ \hline
first & 1 & 4 & 6 & 7 \\ \hline
second & 1 & 4 & 6 & 7 \\ \hline
\end{tabular}
\end{table}
也可以设置数字项中的小数位数:
>>> x.set_decimal_places(4)
>>> print(x)
----------------------------------------------
| Name | b | c | d | e |
+--------+--------+--------+--------+--------+
| first | 1.0000 | 4.0000 | 6.0000 | 7.0000 |
+--------+--------+--------+--------+--------+
| second | 1.0000 | 4.0000 | 6.0000 | 7.0000 |
----------------------------------------------
列还允许数据是元组或列表。但是,小数位不适用于:
>>> x.add_row(['third',[1,1,1], [], (1,1,1),()])
----------------------------------------------------
| Name | b | c | d | e |
+--------+-----------+--------+-----------+--------+
| first | 1.0000 | 4.0000 | 6.0000 | 7.0000 |
+--------+-----------+--------+-----------+--------+
| second | 1.0000 | 4.0000 | 6.0000 | 7.0000 |
+--------+-----------+--------+-----------+--------+
| third | [1, 1, 1] | [] | (1, 1, 1) | () |
----------------------------------------------------
只有交叉线:
>>> x.set_design_property("lines", 'T')
将同时更新ASCII表和Latex表:
>>> print(x)
Name | b c d e
--------+--------
first | 1 4 6 7
second | 1 4 6 7
>>> print(x.build_latex())
\begin{table}
\caption{\label{Tab:}}
\begin{tabular}{l|llll}
Name & b & c & d & e \\ \hline
first & 1 & 4 & 6 & 7 \\
second & 1 & 4 & 6 & 7 \\
\end{tabular}
\end{table}
还有一个选项可以在表中包含所有行(默认选项):
>>> x.set_design_property("lines", 'A')
--------------------------
| Name | b | c | d | e |
+--------+---+---+---+---+
| first | 1 | 4 | 6 | 7 |
+--------+---+---+---+---+
| second | 1 | 4 | 6 | 7 |
--------------------------
或者使用不同科学期刊的格式:
>>> x.set_design_property("lines", 'MNRAS') # monthly notices of the royal astronomical society
--------------
Name b c d e
--------------
first 1 4 6 7
second 1 4 6 7
要将数据存储到文件:
>>> x.write_to_file("<path>_<to>_<file>", mode='a', write_table = True, write_LaTeX=False)
# mode is the normal file.write mode
# write_table to write the ASCII table
# write_LaTeX to write the latex code to build the table
1.0路线图
- 添加更多常见的乳胶表样式:
- []A&A(表和长表)
- []亚太及日本地区
- 功能:
- [x] 删除行和列
- [x] 改变乳胶柱排列的简便方法
- []允许添加额外的垂直线和水平线
- 生活质量:
- []测试多种功能
- []持续集成
- []适当的文档
- 项目
标签: