From d1674cbdb5d501e92d3451b952eb73cdb23cf1d4 Mon Sep 17 00:00:00 2001 From: leogoldman Date: Wed, 2 Feb 2022 16:29:27 -0500 Subject: [PATCH 1/3] Add ability to set latex text size --- stargazer/stargazer.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stargazer/stargazer.py b/stargazer/stargazer.py index 7bfd2c1..314ede6 100644 --- a/stargazer/stargazer.py +++ b/stargazer/stargazer.py @@ -108,6 +108,7 @@ def reset_params(self): self.custom_notes = [] self.show_stars = True self.table_label = None + self.latex_text_size = "" def extract_data(self): """ @@ -274,6 +275,13 @@ def append_notes(self, append): assert type(append) == bool, 'Please input True/False' self.notes_append = append + def latex_size(self, size): + latex_sizes = [ "tiny", "scriptsize", "footnotesize", "small", "normalsize", + "large", "Large", "LARGE", "huge", "Huge" ] + assert type(size) == str, "Please input a string argument for latex text size among:\n"+str(latex_sizes) + assert size in latex_sizes, "Please input a valid latex text size among the following:\n"+str(latex_sizes) + self.latex_text_size = size + def render_html(self, *args, **kwargs): return HTMLRenderer(self).render(*args, **kwargs) @@ -637,7 +645,8 @@ def render(self, only_tabular=False, insert_empty_rows=False): def generate_header(self, only_tabular=False): header = '' if not only_tabular: - header += '\\begin{table}[!htbp] \\centering\n' + size = "" if self.latex_text_size == "" else "\\"+self.latex_text_size + header += '\\begin{table}[!htbp] \\centering ' + size + ' \n' if not self.show_header: return header From a434c1091ff8335a39489c20681812c9628878e4 Mon Sep 17 00:00:00 2001 From: leogoldman Date: Thu, 3 Mar 2022 16:07:33 -0500 Subject: [PATCH 2/3] Changed latex_font_size to add_custom_latex_code --- stargazer/stargazer.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/stargazer/stargazer.py b/stargazer/stargazer.py index 314ede6..f3521b1 100644 --- a/stargazer/stargazer.py +++ b/stargazer/stargazer.py @@ -108,7 +108,7 @@ def reset_params(self): self.custom_notes = [] self.show_stars = True self.table_label = None - self.latex_text_size = "" + self.custom_latex_code = "" def extract_data(self): """ @@ -275,12 +275,12 @@ def append_notes(self, append): assert type(append) == bool, 'Please input True/False' self.notes_append = append - def latex_size(self, size): - latex_sizes = [ "tiny", "scriptsize", "footnotesize", "small", "normalsize", - "large", "Large", "LARGE", "huge", "Huge" ] - assert type(size) == str, "Please input a string argument for latex text size among:\n"+str(latex_sizes) - assert size in latex_sizes, "Please input a valid latex text size among the following:\n"+str(latex_sizes) - self.latex_text_size = size + def add_custom_latex_code(self, code): + assert type(code) in [ list, str ], "Please input custom latex code as a string or list of strings" + if type(code) == list: + assert sum([int(type(n) != str) for n in code]) == 0, "Custom latex code must be strings" + code = " ".join( code ) + self.custom_latex_code += code def render_html(self, *args, **kwargs): return HTMLRenderer(self).render(*args, **kwargs) @@ -304,6 +304,12 @@ def render_latex(self, *args, escape=False, **kwargs): """ return LaTeXRenderer(self, escape=escape).render(*args, **kwargs) + def set_font_size( self, size ): + if type( size ) == str: + size = size if size[0]=="\\" else "\\"+size + self.add_custom_latex_code = size + self.add_custom_latex_code + + class Renderer: """ @@ -645,8 +651,7 @@ def render(self, only_tabular=False, insert_empty_rows=False): def generate_header(self, only_tabular=False): header = '' if not only_tabular: - size = "" if self.latex_text_size == "" else "\\"+self.latex_text_size - header += '\\begin{table}[!htbp] \\centering ' + size + ' \n' + header += '\\begin{table}[!htbp] \\centering ' + self.custom_latex_code + ' \n' if not self.show_header: return header From 3bdacc9f504ce363897b64ce4bb42f38b8fcb191 Mon Sep 17 00:00:00 2001 From: leogoldman Date: Thu, 3 Mar 2022 16:55:19 -0500 Subject: [PATCH 3/3] Added support for numeric font size used in html tables --- stargazer/stargazer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stargazer/stargazer.py b/stargazer/stargazer.py index f3521b1..803726f 100644 --- a/stargazer/stargazer.py +++ b/stargazer/stargazer.py @@ -109,6 +109,7 @@ def reset_params(self): self.show_stars = True self.table_label = None self.custom_latex_code = "" + self.font_size = 100 def extract_data(self): """ @@ -308,7 +309,10 @@ def set_font_size( self, size ): if type( size ) == str: size = size if size[0]=="\\" else "\\"+size self.add_custom_latex_code = size + self.add_custom_latex_code - + if type( size ) in [ int,float ]: + self.font_size = size + else: + assert False, "Please input font size as a string (for latex sizes) or a number for scaling (default=100)" class Renderer: @@ -428,7 +432,7 @@ def generate_header(self): if self.title_text is not None: header += self.title_text + '
' - header += '' if self.dep_var_name is not None: header += '