0

i am using Pylatex in order to generate automatic reports.

In order to generate Table from a dataframe i am using the following function:

def createTable(doc,df,TableTitle):
    with doc.create(Table(position='htbp')) as table:
        table.add_caption(TableTitle)
        table.append(Command('centering'))
        table.append(NoEscape(df.to_latex(escape=False)))

The thing is i get a pdf file where some of the columns of the dataframe are sliced.

How i can fix this issue? how i can apply width parameter in this table creation?

1

Fixed! just added the two lines below:

doc.packages.append(Package('adjustbox'))
doc.append(NoEscape(r'\begin{adjustbox}{width=1\textwidth}'))
table.append(NoEscape(df.to_latex(escape=False)))
doc.append(NoEscape(r'\end{adjustbox}'))
  • While this works, it will reduce the font size, which is not ideal. It's possible to change the setup of the table via options to the to_latex method, for example you can change the column types with the column_format option. It's hard to give more specific advice without knowing what's in the table though. – Torbjørn T. Jul 24 '19 at 19:18
  • Thanks! Basically ill try to play with the parameters of the function as well – Sasha Jul 25 '19 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.