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 all commits
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
22 changes: 20 additions & 2 deletions stargazer/stargazer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def reset_params(self):
self.custom_notes = []
self.show_stars = True
self.table_label = None
self.custom_latex_code = ""
self.font_size = 100

def extract_data(self):
"""
Expand Down Expand Up @@ -274,6 +276,13 @@ def append_notes(self, append):
assert type(append) == bool, 'Please input True/False'
self.notes_append = append

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 @@ -296,6 +305,15 @@ 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
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:
"""
Expand Down Expand Up @@ -414,7 +432,7 @@ def generate_header(self):
if self.title_text is not None:
header += self.title_text + '<br>'

header += '<table style="text-align:center"><tr><td colspan="'
header += '<table style="text-align:center; font-size:{0}%"><tr><td colspan="'.format( str(self.font_size) )
header += str(self.num_models + 1) + '" style="border-bottom: 1px solid black"></td></tr>'
if self.dep_var_name is not None:
header += '<tr><td style="text-align:left"></td><td colspan="' + str(self.num_models)
Expand Down Expand Up @@ -637,7 +655,7 @@ 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'
header += '\\begin{table}[!htbp] \\centering ' + self.custom_latex_code + ' \n'
if not self.show_header:
return header

Expand Down