Search code examples
rr-markdownmarkdowncss-tables

column widths in markdown tables embedded in rmarkdown documents


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 | |

Solution

  • 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 | |