How to vertically rotate and center-align text inside a table cell (react-pdf/renderer) #3157
RauschkugelxD
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I recently ran into a tricky layout issue using
react-pdf, and since I couldn’t find a clear solution online, I wanted to share what worked for me.🧩 The Problem
I needed to render vertically rotated text inside a table cell with fixed dimensions – only as wide as the rotated text required – and have it centered, both vertically and horizontally. Despite the cell having enough height to fit the rotated text, it kept wrapping, as if it were still being measured horizontally.
My hypothesis: It seems the layout dimensions are calculated before applying transforms, so the
rotate(-90deg)is only visually applied after wrapping logic. The result: even though the rotated text would fit, the text wraps prematurely due to the narrow width.✅ The Solution
After some experimentation, I found a simple workaround:
flexDirection: "column"on the cell and center the text along both axes.Hopefully this helps others running into the same issue when rotating text in table layouts.
If you have a better explanation for why this happens – or a cleaner solution – I’d love to hear it! 😊
Beta Was this translation helpful? Give feedback.
All reactions