@@ -171,13 +171,21 @@ def _latex_line_begin_tabular(colwidths, colaligns,booktabs=False):
171
171
datarow = partial (_mediawiki_row_with_attrs , "|" ),
172
172
padding = 0 , with_header_hide = None ),
173
173
"latex" :
174
- TableFormat (lineabove = _latex_line_begin_tabular ,
174
+ TableFormat (lineabove = lambda x , y : _latex_line_begin_tabular ( x , y , False ) ,
175
175
linebelowheader = Line ("\\ hline" , "" , "" , "" ),
176
176
linebetweenrows = None ,
177
177
linebelow = Line ("\\ hline\n \\ end{tabular}" , "" , "" , "" ),
178
178
headerrow = DataRow ("" , "&" , "\\ \\ " ),
179
179
datarow = DataRow ("" , "&" , "\\ \\ " ),
180
180
padding = 1 , with_header_hide = None ),
181
+ "latex_booktabs" :
182
+ TableFormat (lineabove = lambda x ,y :_latex_line_begin_tabular (x ,y ,True ),
183
+ linebelowheader = Line ("\\ midrule" , "" , "" , "" ),
184
+ linebetweenrows = None ,
185
+ linebelow = Line ("\\ bottomrule\n \\ end{tabular}" , "" , "" , "" ),
186
+ headerrow = DataRow ("" , "&" , "\\ \\ " ),
187
+ datarow = DataRow ("" , "&" , "\\ \\ " ),
188
+ padding = 1 , with_header_hide = None ),
181
189
"tsv" :
182
190
TableFormat (lineabove = None , linebelowheader = None ,
183
191
linebetweenrows = None , linebelow = None ,
@@ -566,7 +574,7 @@ def _normalize_tabular_data(tabular_data, headers):
566
574
567
575
def tabulate (tabular_data , headers = [], tablefmt = "simple" ,
568
576
floatfmt = "g" , numalign = "decimal" , stralign = "left" ,
569
- missingval = "" , booktabs = "False" ):
577
+ missingval = "" ):
570
578
"""Format a fixed width table for pretty printing.
571
579
572
580
>>> print(tabulate([[1, 2.34], [-56, "8.999"], ["2", "10001"]]))
@@ -636,7 +644,7 @@ def tabulate(tabular_data, headers=[], tablefmt="simple",
636
644
637
645
Various plain-text table formats (`tablefmt`) are supported:
638
646
'plain', 'simple', 'grid', 'pipe', 'orgtbl', 'rst', 'mediawiki',
639
- and 'latex'. Variable `tabulate_formats` contains the list of
647
+ 'latex', and 'latex_booktabs '. Variable `tabulate_formats` contains the list of
640
648
currently supported formats.
641
649
642
650
"plain" format doesn't use any pseudographics to draw tables,
@@ -762,17 +770,17 @@ def tabulate(tabular_data, headers=[], tablefmt="simple",
762
770
\\ hline
763
771
\\ end{tabular}
764
772
773
+ "latex_booktabs" produces a tabular environment of LaTeX document markup
774
+ using the booktabs.sty package:
775
+
776
+ >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="latex_booktabs"))
777
+ \\ begin{tabular}{lr}
778
+ \\ toprule
779
+ spam & 41.9999 \\ \\
780
+ eggs & 451 \\ \\
781
+ \\ bottomrule
782
+ \end{tabular}
765
783
"""
766
- # If users have the booktabs package loaded in LaTeX and set the booktabs argument to True,
767
- # modify the rules inserted into the table.
768
- if booktabs :
769
- _table_formats ["latex" ] = TableFormat (lineabove = lambda x ,y :_latex_line_begin_tabular (x ,y ,True ),
770
- linebelowheader = Line ("\\ midrule" , "" , "" , "" ),
771
- linebetweenrows = None ,
772
- linebelow = Line ("\\ bottomrule\\ end{tabular}" , "" , "" , "" ),
773
- headerrow = DataRow ("" , "&" , "\\ \\ " ),
774
- datarow = DataRow ("" , "&" , "\\ \\ " ),
775
- padding = 1 , with_header_hide = None )
776
784
777
785
list_of_lists , headers = _normalize_tabular_data (tabular_data , headers )
778
786
0 commit comments