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

Support text justification for individual cells/rows/columns in ggtexttable() #335

Closed
winkel111 opened this issue Sep 2, 2020 · 5 comments

Comments

@winkel111
Copy link

Although text justification was added to ggtexttable (#18), the justification setting always applies to the entire table.
It would be great if we could change the text justification for individual cells or rows/columns similar to table_cell_bg() or table_cell_font(). Having this option would be super useful. Thank you!

@winkel111 winkel111 changed the title Support text justification for individual columns in ggtexttable Support text justification for individual cells/rows/columns in ggtexttable() Sep 2, 2020
@tschoesi
Copy link

tschoesi commented Sep 16, 2020

Also very interested in this (or a workaround that allows to change the justification of just a single column)!

Edit: changing justification row wise can be done by passing a list i.e. c(0,0,5) to make every other column left aligned or centered.
Edit2: to set justification for each column separately pass the following as the hjust argument:
as.vector(matrix(c(0, 0.5, 1), ncol=3, nrow=nrow(dataframe), byrow=TRUE)) (for 3 columns & where dataframe is your dataframe...)

@acdelre
Copy link

acdelre commented Dec 19, 2022

Can someone give an example of how to left justify the 1st column and right justify the rest? I cannot get the example above to work

@acdelre
Copy link

acdelre commented Dec 20, 2022

using this: theme = ggpubr::ttheme(tbody.style = ggpubr::tbody_style(hjust=as.vector(matrix(c(1, 0, 0,0),
ncol=4, nrow=nrow(MY_DATA),
byrow=TRUE)))
I can get the 1st column (sort of) left justified and the other 3 columns right justified (correctly) but the 1st column has the alignment left but flush right (so there ends up being space on the left side of the column), e.g.

john smith
jeffe smiths
sam smith
j smith

how can I get it left justified and flush left for the 1st column? thanks!

@acdelre
Copy link

acdelre commented Dec 20, 2022

I figured it out:
ggpubr::ttheme(tbody.style = ggpubr::tbody_style(hjust=as.vector(matrix(c(0, 1, 1,1),
ncol=4, nrow=nrow(sub),
byrow=TRUE)), x = as.vector(matrix(c(.1, .9, .9,.9),
ncol=4, nrow=nrow(sub),
byrow=TRUE)))

@kassambara
Copy link
Owner

doc updated now with an example, thank you all for the contribution to the discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants