Search code examples
pythonpdfjupyternbconvert

How to get the same look of table when generating pdf from jupyter notebook?


I have a jupyter notebook python based where I have dataframe output shown- it is 5 columns size. It looks fine in notebook but when I generate pdf using nbconvert command it is being split and only two columns are shown at once

I use custom template, I have an idea to change a bit the size of font in table or wrap the text in column but I cannot find how to address this sort of problem in it. I tried the PrettyTable class from http://blog.juliusschulz.de/blog/ultimate-ipython-notebook It looks better however it get cut off one column when the text in previous is longer


Solution

  • I finally managed it with rather workaround than final solution,I used PrettyTable from Julius Schulz (http://blog.juliusschulz.de/blog/ultimate-ipython-notebook) and in the template I lowered the size of font in tables for whole document by using this:

    ((* block docclass *))
    \documentclass[11pt,a4paper,prb]{article}
    
    \usepackage{placeins,booktabs,array,tabularx,xparse,authblk}
    
    \AtBeginDocument{
    \let\oldtabular\tabular 
    \renewcommand{\tabular}{\tiny\oldtabular}
    }
    
    ((* endblock docclass *))
    

    However I think it should be rather done by wrapping-for this I didn't find the solution.