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

Table with percentages not rendered correctly #372

Closed
filiphr opened this issue Dec 15, 2015 · 15 comments
Closed

Table with percentages not rendered correctly #372

filiphr opened this issue Dec 15, 2015 · 15 comments
Assignees
Labels
Milestone

Comments

@filiphr
Copy link

filiphr commented Dec 15, 2015

I have been trying to create some tables with percentages for the cols and I am getting a CannotFit from Prawn. I am not sure if this is a Prawn problem or something from the pdf generator.

An example table is the following;

.Table title
[cols="e,e,40%"]
|===
|Header 1 |Header 2 |Header 3

|Column 1, row 1
|Column 2, row 1
|Column 3, row 1

|Column 1, row 2
|Column 2, row 2
|Column 3, row 2

|Column 1, row 3
|Column 2, row 3
|Column 3, row 3
|===

Is there some way to create a table with percentages for the columns and create pdf from it?

@mojavelinux
Copy link
Member

AsciiDoc uses relative values, not percentages. The default value for a column is 1. The values are adjusted to add up to 100, so it makes sense to write them that way.

The proper way to write the table header in your example is as follows:

[cols="30e,30e,40"]
|===
|Header 1 |Header 2 |Header 3

Technically, e,e,40 should work, but it appears we have a rounding error with the resolved values of 2,2,95 such that it thinks the amount is more than 100. I'll look into that.

@mojavelinux
Copy link
Member

it appears we have a rounding error

from the looks of it, a major one. Trying to get to the bottom of it.

@mojavelinux
Copy link
Member

Aha, I see what it is. The problem isn't the total column widths (though there is still a small rounding error there). When you get the error CannotFit, it means that one of the columns is too narrow to fit the content within it. That means you need to expand the size of the column.

@mojavelinux mojavelinux added this to the support milestone Dec 16, 2015
@filiphr
Copy link
Author

filiphr commented Dec 16, 2015

Thanks a lot for your fast reply. It helped me a lot.

However, it seems that there might be some rounding problems as well (It cannot be that the column is too narrow for the column, in this case). I tried the following table:

.Table title
[cols="6*e,30e,30e"]
|============================
7.1+|N|B

7.1+|*T*|T
| 2.1+| 4.1+|T|T
| 3.1+| 3.1+|T|T
| 4.1+| 2.1+|T|T
| 4.1+| 2.1+|T|T
| 3.1+| 3.1+|T|T

| 2.1+| 4.1+|T|T
| 4.1+| 2.1+|T|T
| 4.1+| 2.1+|T|T
| 4.1+| 2.1+|T|T
| 5.1+| 1.1+|T|T

| 2.1+| 4.1+|T|T
| 3.1+| 3.1+|T|T
| 3.1+| 3.1+|T|T
| 3.1+| 3.1+|T|T

| 2.1+| 4.1+|T|T
| 3.1+| 3.1+|T|T
| 3.1+| 3.1+|T|T

| 2.1+| 4.1+|T|T

|============================

And I am getting
SEVERE: (CannotFit) Table's width was set larger than its contents' maximum width (max width 494.8991999999999, requested 515.52).

If the second columns are 47 instead of 30 it works.

Another point is. If I use the asciidoctor-pdf generator then the table is spread over 2 pages, I want it to be on one page, not 2 pages. I am using the doctype article when doing the conversion. Am I doing something wrong?
When I create a pdf with the docbkx maven plugin the table is properly done.

@mojavelinux
Copy link
Member

SEVERE: (CannotFit) Table's width was set larger than its contents' maximum width (max width 494.8991999999999, requested 515.52).

There's a fix for this in master, not the released version.

I don't understand what your table is supposed to look like, but what I'm seeing in the HTML output seems incorrect.

If the second columns are 47 instead of 30 it works.

There is a bug in core that causes the columns to not add up to 100% when the values aren't based on 100. Therefore, you should ensure that your numbers add up to 100 and you'll work around this issue.

If I use the asciidoctor-pdf generator then the table is spread over 2 pages, I want it to be on one page, not 2 pages. I am using the doctype article when doing the conversion. Am I doing something wrong?

No, this is not yet supported. See #331.

When I create a pdf with the docbkx maven plugin the table is properly done.

These are orthogonal things. That's a different tool and thus has different behavior.

@filiphr
Copy link
Author

filiphr commented Dec 17, 2015

Good to know about the fix,

As for the table. The HTML content looks like I expect it to look. As for the pdf it doesn't. Only half of the table is shown (the B column is missing) . Please have a look
table.pdf
table.html

@mojavelinux
Copy link
Member

Thanks for the samples. What is the table supposed to be? (what is it used for?)

@filiphr
Copy link
Author

filiphr commented Dec 17, 2015

I want to create a table that will look something like folder tree. We need to show how the contents of a delivery look like and what is contained in what.

The last 2 columns are use for text and the other columns are used to depict folder levels. So for example row 3 has level 2, row 4 has 3, row 5 has 4.

Row 1 starts after the header.
Here is a table with more descriptive columns:

.Table title
[cols="6*e,47e,47e"]
|============================
7.1+|Name|Description

7.1+|*Root Folder*|T
| 2.1+| 4.1+|Folder lvl2|T
| 3.1+| 3.1+|Folder lvl3|T
| 4.1+| 2.1+|File in Folder lvl3|T
| 4.1+| 2.1+|File in Folder lvl3|T
| 3.1+| 3.1+|File in lvl2|T
|============================

For some reason I am getting

SEVERE: (CannotFit) Table's width was set too small to contain its contents (min width >732.8975999999999, requested 515.52)

when I try to generate the pdf.

@mojavelinux
Copy link
Member

I want to create a table that will look something like folder tree.

I was slightly afraid you were going to say that. I do want to address this issue, because the table should definitely work as designed, for your case, I'm not sure this is the best approach.

This is where I think you might want to think about a custom block so you have 100% control over the output. Asciidoctor isn't really a general purpose layout engine. If you can make the built-in controls stretch to your use case, there certainly no harm in it. But if you find yourself fighting it, then it's probably wiser to take over control of the layout. A custom block enables you to get a callback and handle the output for that node using the low-level format (HTML, PDF, etc).

@mojavelinux
Copy link
Member

For some reason I am getting...

are you using master?

@filiphr
Copy link
Author

filiphr commented Dec 17, 2015

No, I am using the last release from asciidoctor-pdf 1.5.0-alpha.10.1 with asciidoctor version 1.5.3.2. I am using the maven plugin as well.

I just started using asciidoc and asciidoctor, so I don't have a lot of experience with custom blocks and so on. Maybe I should have a look at it a bit more. We are thinking to both release a HTML and PDF version of the documentation, so I want to avoid using backend specific format as much as possible

@mojavelinux
Copy link
Member

The reason I ask if you are using master is because I applied a calculation bug on master so it doesn't overrun the table width. If you are using a release, then you are likely going to keep getting this issue under different circumstances. I plan to do another alpha this weekend that should have the fix.

@mojavelinux
Copy link
Member

What's important is that I'm now aware that there is a calculation error that needs to be addressed and I'll focus on that as part of this issue. One way or another, we can get these columns to be calculated correctly.

@mojavelinux
Copy link
Member

so I want to avoid using backend specific format as much as possible

I strongly encourage you to dive into it as soon as you can. That's where all the flexibility is in Asciidoctor and it opens up important doors for productivity when you do so. There are many ways to write extensions (Ruby, Java, Groovy) and lots of help in the community, so there's no reason to fear it.

@mojavelinux
Copy link
Member

Asciidoctor 1.5.4 calculates column widths correctly (such that they add up to 100%). There's also a fix in Asciidoctor PDF to work with earlier versions of Asciidoctor. If this continues to be an issue, feel free to reopen or, ideally, open a new issue.

@mojavelinux mojavelinux self-assigned this Sep 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants