texttable库的一个扩展,它直接将表导出到Latex。
latextable的Python项目详细描述
可延迟
Texttable是一个Python包,可以创建简单的ASCII表。 这个包扩展了它的功能,允许表直接以Latex格式输出,从而消除了繁琐的复制和粘贴工作。 Latex输出与表设计相匹配,并且有用于添加表标题和标签的实用程序。在
特点
- 以Latex格式绘制表对象。在
- 匹配表装饰(边框、标题、hline、vlines)。在
- 应用水平列对齐。在
- 允许用户从输出中删除某些列。在
- 提供向Latex输出添加标题和引用标签的功能。在
- 输出是正确的缩进直接复制到乳胶。在
安装
PyPi:
pip install latextable
要求:
^{pr2}$使用
单个函数latextable.draw_latex
根据提供的表返回格式化的Latex字符串。在
draw_latex(table, caption=None, label=None, drop_columns=None)
table: Texttable table to be rendered in Latex.
caption: A string that adds a caption to the Latex formatting.
label: A string that adds a referencing label to the Latex formatting.
drop_columns: A list of column names that won't be in the Latex output.
Each column name must be in the table header.
return: The formatted Latex table returned as a single string.
示例
这些示例使用Texttable文档中提供的现有表。在
用法:
table = Texttable()
table.set_cols_align(["l", "r", "c"])
table.set_cols_valign(["t", "m", "b"])
table.add_rows([["Name", "Age", "Nickname"],
["Mr\nXavier\nHuon", 32, "Xav'"],
["Mr\nBaptiste\nClement", 1, "Baby"],
["Mme\nLouise\nBourgeau", 28, "Lou\n \nLoue"]])
print(table.draw() + "\n")
print(latextable.draw_latex(table, caption="An example table.") + "\n")
table = Texttable()
table.set_deco(Texttable.HEADER)
table.set_cols_dtype(['t', # text
'f', # float (decimal)
'e', # float (exponent)
'i', # integer
'a']) # automatic
table.set_cols_align(["l", "r", "r", "r", "l"])
table.add_rows([["text", "float", "exp", "int", "auto"],
["abcd", "67", 654, 89, 128.001],
["efghijk", 67.5434, .654, 89.6, 12800000000000000000000.00023],
["lmn", 5e-78, 5e-78, 89.4, .000000000000128],
["opqrstu", .023, 5e+78, 92., 12800000000000000000000]])
print(table.draw() + "\n")
print(latextable.draw_latex(table, caption="Another table.", label="table:another_table") + "\n")
print(latextable.draw_latex(table, caption="A table with dropped columns.", label="table:dropped_column_table", drop_columns=['exp', 'int']))
乳胶产量:
\begin{table}
\begin{center}
\begin{tabular}{|l|r|c|}
\hline
Name & Age & Nickname \\
\hline
MrXavierHuon & 32 & Xav' \\
\hline
MrBaptisteClement & 1 & Baby \\
\hline
MmeLouiseBourgeau & 28 & Lou Loue \\
\hline
\end{tabular}
\end{center}
\caption{An example table.}
\label{table:example_table}
\end{table}
\begin{table}
\begin{center}
\begin{tabular}{l r r r l}
text & float & exp & int & auto \\
\hline
abcd & 67.000 & 6.540e+02 & 89 & 128.001 \\
efghijk & 67.543 & 6.540e-01 & 90 & 1.280e+22 \\
lmn & 0.000 & 5.000e-78 & 89 & 0.000 \\
opqrstu & 0.023 & 5.000e+78 & 92 & 1.280e+22 \\
\end{tabular}
\end{center}
\caption{Another table.}
\label{table:another_table}
\end{table}
\begin{table}
\begin{center}
\begin{tabular}{l r r r l}
text & float & auto \\
\hline
abcd & 67.000 & 128.001 \\
efghijk & 67.543 & 1.280e+22 \\
lmn & 0.000 & 0.000 \\
opqrstu & 0.023 & 1.280e+22 \\
\end{tabular}
\end{center}
\caption{A table with dropped columns.}
\label{table:dropped_column_table}
\end{table}
发布历史记录
- 0.1.1节
- 对文档的微小更改。在
- 0.1.0款
- 初次发行
元
Joseph Early
@JosephAEarly
joseph.early.ai@gmail.com
根据麻省理工学院的许可证分发。有关详细信息,请参见LICENSE
。在
- 项目
标签: