-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 center alignment #72
Comments
wow, this made me think; I was about to answer: sure it is ;) but had troubles to provide an example it looks like alignment is not taken into consideration in this case, I'll have to take a look at it currently you can use the following workaround:
|
nice, that does the job! |
it would be nice to have a table sizing that sizes all other the cells according to the largest content i.e. cellSize = max(cellSize) or failing that, get text metrics to calculate cell size yourself |
you mean equal widths for all columns based on largest width? |
Hi, Could you please help me out fast. Thanks. |
what do you mean it didn't work? include your doc definition object, otherwise it's difficult to figure out what kind of problem you have |
@bpampuch .. Thank you for the quick response. The table is not getting center aligned if my no. of columns are less. This trick which you have given dint work. { The pdf is working perfectly for the table which has more number of columns. This is how I am getting the table : |
the trick is to have first and last column start-sized; change |
That is what I am doing exactly. The exact code is : content : [
|
still can't reproduce this, could you include a complete example? thx |
@bpampuch : Here is the actual code written for the same. I have removed the actual image data, due to the identity issue. var pageOrientation;
|
Hi @bpampuch .. Did you work on this issue. I have tried but could not get it worked. |
I have been struggling with this problem and I have found that, although it may be possible to workaround in some cases, there is a single point that makes a definite solution really hard to find. @bpampuch workaround works for that specific case and @blushi pull request helps a lot. But both leave one problem unsolved. The column approach causes pdfmake to crash when the table to be center aligned has any column width defined in %:
@blushi pull request cannot properly centralize a table inside another table cell which is definied in %:
Both fail for the same reason: there is currently no treatment for column widths in % when it first attempts to calculate the column widths in points when tryLayoutDocument() does Then it reaches measureTable(), which calls measureMinMax() happens to be:
The line I commented I belive that a test for % width column is missing. In the column workaround, the last else is reached with c.width = "80%", variable result therefore becomes:
... which are not valid numbers. It seems not to be an easy task to implement the missing else clause (test for % width) as the code at this point have no clue about the available width there is left for it to use so it could calculate the effective width in points. The availableWidth is only calculated later in the processing phase by buildColumnWidths() called either from layoutBuilder.js (for comuns) or tableProcessor.js (for tables). As far as I understand the problem, it seems to me that some refactoring is needed in order to measureTable() be able to receive the available width and properly measure the table. Does anyone have another idea? One thing I could no realize yet is how the star widths are being properly solved, perhaps % widths could work in a similar manner. |
Just use '*' instead of int in widths option, and you are good to go |
here we are... 7 years later and the issue is still present. 🙃 btw thank you very much, @bpampuch. your workaround worked (although if the content width is big enough it gets off-center to the right for some reason...) |
Thank you for this workaround ;) |
IS it possible to align the table in the center of the page? All the
alignment: 'center',
code I add does nothing
The text was updated successfully, but these errors were encountered: