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

Long tables get truncated when not fitting on a page #50

Open
martijndeb opened this issue May 10, 2019 · 4 comments
Open

Long tables get truncated when not fitting on a page #50

martijndeb opened this issue May 10, 2019 · 4 comments

Comments

@martijndeb
Copy link

Say you have a chapter called "Chapter about Tables", and you generate a table in it that's longer than the page. The table gets pushed to a new page, causing "Chapter about Tables" to be on it's own page with a lot of whitespace.

The table if longer than a page should continue on a new page, instead it's cut off at the bottom part of the page.

(Rename long-table.txt to .md)
long-table.txt

@erilot
Copy link

erilot commented May 23, 2019

@sexybiggetje I'm up against this too, but it seems to be a limitation of Weasyprint and not this plugin.

Kozea/WeasyPrint#36

That issue is 6 years old 😞

@akinmr
Copy link

akinmr commented May 27, 2019

I managed to split such table into multiple pages with the attached modification to themes/material.py in Material theme doc.

tablesplit.diff.txt

Yes, it's a quite dirty hack, but worked.
I tried to find out appropriate style rule to make it work without "!important", but couldn't.

@akinmr
Copy link

akinmr commented May 27, 2019

Oops, I made a mistake in the path of the previous patch, please adjust accordingly.
Also, the table's width becomes 100% as a side-effect, and it might be better to remove border settings to conceal this.
Anyway, I'd like to wait for CSS guru to provide much better solutions.

@erilot
Copy link

erilot commented May 29, 2019

@akinmr Oh nice workaround! I've tested and confirmed that this works.

You don't have to patch anything, just include a custom CSS file (or modify your existing one), and include this in the @media print block like so:

mkdocs.yml

extra_css:
  - 'stylesheets/pdf.css' # for example, this would be the path to your stylesheet

pdf.css

@media print {

    .md-typeset table:not([class]) {
        display: block;
        border: none;
    }
        
}

The increased specificity (table:not([class])) is required to override the theme stylesheet and negates the need for !important. I'm also removing the table border to sidestep the weird 100% width table box effect.

This workaround will only work for material design themes, but you could make it work with any theme by adapting the CSS selector.

Probably could be refined further, particularly if the outside border is important, but this is an easy and acceptable workaround for my purposes.

Thanks for figuring that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants