Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set latex text size #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed latex_font_size to add_custom_latex_code
  • Loading branch information
leogoldman committed Mar 3, 2022
commit a434c1091ff8335a39489c20681812c9628878e4
23 changes: 14 additions & 9 deletions stargazer/stargazer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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

Expand Down