-
Notifications
You must be signed in to change notification settings - Fork 253
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
How to horizontally center a table? align="CENTER" is not working for me #1306
Comments
Hi @DerekRobin Thank you for the report. Despite being mentioned in our documentation: https://py-pdf.github.io/fpdf2/Tables.html#setting-table-column-widths
...it seems that this never worked properly... 😅 I tested the following code with from fpdf import FPDF
TABLE_DATA = (
("First name", "Last name", "Age", "City"),
("Jules", "Smith", "34", "San Juan"),
("Mary", "Ramos", "45", "Orlando"),
("Carlson", "Banks", "19", "Los Angeles"),
("Lucas", "Cimon", "31", "Angers"),
)
pdf = FPDF()
pdf.add_page()
pdf.set_font("Times", size=16)
with pdf.table(col_widths=pdf.epw / 5, align="C") as table:
for data_row in TABLE_DATA:
row = table.row()
for datum in data_row:
row.cell(datum)
pdf.output("./test/table/table_with_fixed_col_width_and_align.pdf") ...and the table is NOT horizontally centered on the page! Wooops. I will look into fix it. |
@allcontributors please add @DerekRobin for bug report |
I've put up a pull request to add @DerekRobin! 🎉 |
Fixed in PR #1308 |
@DerekRobin: while the fix has not been released in a new version published on Pypi, you can test that it works for you using:
Also, note that you will have to either specify a fixed column width (single number When |
What wonderful news to wake up to! Thank you so much :) |
Discussed in #1304
Originally posted by DerekRobin November 19, 2024
I was wondering how to horizontally center a table on the page? I know about the
align
parameter that can be passed when instantiating a table. However, for some reason passingalign="CENTER"
does not align the table to the center of the page.I have included the code I am using to generate the table below from a pandas dataframe (df)
The text was updated successfully, but these errors were encountered: