Skip to content

Feature request: allow horizontal centering in TextStyle #1282

Closed
@Lucas-C

Description

@Lucas-C

Proposed solution

  1. Allow Align.C to be passed as a value for .l_margin in TextStyle
  2. When this .l_margin is used in FPDF._use_title_style(), if it is Align.C, then horizontally align the text

The PR implementing this should include unit tests using FPDF.start_section()

Discussed in #1280

Originally posted by Benoite142 October 10, 2024:

Hi,

I've been trying to center a TitleStyle for quite some time now. I've been using a TitleStyle for the start_section function used in the TOC placeholder and I am having a lot of trouble trying to center the TitleStyle. I know we can easily center some cell or text with align='C' but I found no way of doing that for the TitleStyle. I know we can put a value to the l_margin to make it look like it is centered, but I can't really use that since all of my titles differs in length.

I also tried aligning everything to the center of the page, but that still doesn't work with TitleStyle and the sections.
Worst case scenario is that I put everything on the left, but I would really want it to be centered.

If anyone knows how I could do this, please let me know.

Thank you for you time 😊

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions