vertical alignment of `gt` cell contents

I'm trying to create a gt table and I see that I can control the left/center/right alignment of cell contents with cols_align. Is there any way to control the vertical alignment? I have a column with long wrapping text and I'd like to have the shorter column be aligned with the top. Ideas?

What I have looks like the following... but I want the index to be at the top of each cell:

library(tidyverse)
library(gt)
library(stringi)

df <- data.frame(index=c("I want this","at the top","of each cell"), 
           text = sapply(rep(1,3),stri_rand_lipsum))
df %>% gt()

index

text

I want this

Lorem ipsum dolor sit amet, nostra congue malesuada, at. Blandit libero tortor, torquent. Orci facilisi volutpat eu. Vitae blandit class montes dictumst tellus massa a nunc et sed, diam, sed ac felis nisl. In, nascetur amet mus eleifend, eros dignissim ac consequat lectus potenti. Luctus orci augue id ut. Donec tellus adipiscing integer platea dolor laoreet malesuada. Pharetra accumsan, id eros finibus in blandit ultrices ac. Nec fermentum maximus vitae conubia vestibulum. In neque, blandit adipiscing nunc at in quis ac. Ex etiam venenatis vel eu litora fermentum inceptos et, sed fames. Tincidunt in odio pulvinar ante ac tempor sit. Eleifend, integer orci et tortor, nostra! Sodales vehicula lorem sapien magnis dapibus ac.

at the top

Lorem ipsum dolor sit amet, cras cras nibh pharetra consectetur vel porta nam et. Accumsan arcu nunc sem nulla aliquet, eros imperdiet. Enim quis ut risus donec amet, turpis augue morbi, eget. Egestas vestibulum tellus et proin dictumst maecenas. Himenaeos ut ad neque pharetra aptent id imperdiet et. Et et felis congue purus imperdiet dis quam at ac nec. Curabitur in dictumst nam augue dolor mauris in. Primis vehicula sociis ut efficitur malesuada feugiat imperdiet id. Rhoncus tincidunt primis per cras nostra tincidunt justo taciti? Vel integer interdum ultricies nisi interdum sem vitae. Semper, cum velit donec eu. Feugiat netus eget.

of each cell

Lorem ipsum dolor sit amet, dictum nibh habitant ante lacinia nulla lorem ut tempus facilisis. Metus amet lectus curae tellus dolor. Dapibus in mauris magna, mus. Diam ipsum porttitor, imperdiet ante etiam amet habitasse ornare suscipit, in nulla nec. Vehicula velit cubilia sed tortor sit sed, ut, vel commodo commodo. Mollis, nisi eu nisl maecenas cubilia. Tincidunt in ac donec tempor in vestibulum, porttitor potenti arcu eleifend habitant, at. Velit lectus varius sagittis ex quam quis ligula natoque. Dui torquent eu mauris faucibus porta tortor ad erat molestie. Risus penatibus maecenas in ex nisi, ullamcorper.

Created on 2019-02-05 by the reprex package (v0.2.1)

I can't find the gt package on CRAN. Where's it from?

it's not yet on CRAN: https://gt.rstudio.com

You can pass the css attribute of vertical-align:top to your table using tab_style:

df %>% gt() %>% 
  tab_style(
    style = "vertical-align:top",
    locations = cells_data(
      columns = vars(index)
      )
  ) 
5 Likes

thanks Josh. I was hoping it was something straight forward like that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.