Search code examples
pandaslatexoverleaf

Pandas to_latex - format table width at export or in overleaf


I'm exporting a pandss dataframe as tex file for my overleaf project, like so:

df.to_latex('df.tex')

when I import the file into my project:

\begin{table}[H]
\centering
\input{df}
\end{table}

enter image description here

It does not fit the page.

I wonder if there's any way of formatting my width of font size or else as I export the file, or making it fit, after importing the file with \input.

I have tried using \centering, to no avail.


Solution

  • You can set the font size before you import the table, e.g.

    \begin{table}[H]
    \centering
    \tiny % or whatever font size suites your needs
    \input{df}
    \end{table}
    

    Alternatively you could give your numbers with a reasonable number of significant digits, this would surely safe tons of space.