column widths in markdown tables embedded in rmarkdown documents
Asked Answered
P

1

0

Is it possible to set column widths with markdown tables in Rmarkdown? When the text in column 2 gets long the table goes to an equal split between cols 1 and 2. I reviewed answers to what seems like a similar question but nothing seems to be quite right.

I'd like something closer to Version 1 compared to Version 2.

enter image description here

---
title: "Untitled"
output: 
  bookdown::html_document2:
    toc: true
    toc_float: true
    toc_depth: 1
    code_folding: show
    theme: default
    highlight: tango
---

# Version 1

| Something | Else |
|:--|:--|
| Short | This is longer this is longer this is longer  |
| Short | |

# Version 2

| Something | Else |
|:--|:--|
| Short | This is longer this is longer this is longer this is longer this is longer this is longer |
| Short | |
Prototrophic answered 19/7, 2020 at 15:20 Comment(2)
If you're creating your table using kable() from knitr, then column_spec in kableExtra should give you what you want. See here.Herod
Thanks, @Limey. No, I'm just creating pipe-style tables in markdown.Prototrophic
G
5

One easy way how it should work with many parsers is to use different relative widths in your table definition, such as like this:

| Something | Else |
|---------------|------------------------------------------------------------------------------------------------------|
| Short | This is longer this is longer this is longer this is longer this is longer this is longer this is longer this is longer this is longer this is longer this is longer this is longer |
| Short | |
Glottal answered 19/7, 2020 at 23:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.