可以导出到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] 改变乳胶柱排列的简便方法
    • []允许添加额外的垂直线和水平线
  • 生活质量:
    • []测试多种功能
    • []持续集成
    • []适当的文档

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
图形Java仿射变换以旋转通用路径   IntelliJ IDEA中的java代码标记为编译器错误,在Eclipse中可以正常工作   java ArrayList的containsAll返回了错误的值   如何在安卓中的片段活动中添加java代码   java通过使用netbeans调用jbutton,将带有行的jbutton添加到jtable中   java在更新arrayAdapter/listView之前更新最终列表   java如何在另一个项目中导入包含AspectJ方面和注释的项目   为什么我的java布尔测试总是失败?   Eclipse中的java自动激活   在Bluetooth for Java(更具体地说是Android)之上是否有TCP/IP协议栈实现?   java Android Studio通过intent传递ArrayList并填充ListView