[Tex/LaTex] df.to_latex() table width pylatex

pylatextables

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?

Best Answer

Fixed! just added the two lines below:

doc.packages.append(Package('adjustbox'))
doc.append(NoEscape(r'\begin{adjustbox}{width=1\textwidth}'))
doc.append(NoEscape(df.describe().to_latex()))
doc.append(NoEscape(r'\end{adjustbox}'))