29

Is there a way to control the maximum cell width in a Pandoc table?

For example:

|          |            |
|----------|------------|
| I want to the contents of this cell to fit on one line|   XXXXXXX  |

I want to control how the line in the left cell is broken or, in other words, I want to control the maximum width of a cell.

2
  • Try using a multiline or a grid table. Dec 1, 2014 at 1:16
  • grid table did not help.
    – Mustafa
    Dec 1, 2014 at 2:20

2 Answers 2

26

{CAVEATS: This answer applies to Pandoc only, and only when making use of the multiline_table extension to the input in the Markdown syntax. So it won't work for Github Flavored Markdown (GFM).}


Multiline tables do support the relative width of columns. (However, you will not be able to control exactly where + how the line in any cell is broken.)

See my answer to your other question.

Be aware that this works for LaTeX, PDF and HTML output only, but not necessarily for HTML, ODT, DOCX or other output...


Update

Here is an example, using three different examples of multiline tables. They vary in Markdown as far as the widths of their table header/content separator lines are concerned:

--------------------------------------------------------------------
Column 1                                                Column 2
------------------------------------------------------  ------------
I want the contents of this cell to fit into one line   Word1 Word2

------------------------------------------------------  ------------

: **Column 2 is narrow.** For column 1: 54 dashes in Markdown source 
for separator line; for column 2: 12 dashes in separator line (22% of column 1).


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Column 1                                                Column 2
------------------------------------------------------  ------------------------------------------------------------------------------------------------------------------------------------------------------------------
I want the contents of this cell to fit into one line   Word1 Word2

------------------------------------------------------  ------------------------------------------------------------------------------------------------------------------------------------------------------------------

: **Column 1 is narrow.** For column 1: 54 dashes in Markdown source for
separator line; for column 2: 162 dashes in separator line (300% of column 1).


-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Column 1                                                                                                                                                                                                            Column 2
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ---------------
I want the contents of this cell to fit into one line                                                                                                                                                               Word1 Word2

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ---------------

: **Column 2 is even narrower than in Table 1.** For column 1: 210 dashes 
in Markdown source for separator line; for column 2: 15 dashes in separator 
line (7% of column 1).

Results

  1. PDF

    3 different tables as PDF from multiline-table Markdown

  2. HTML (without much of a stylesheet used)

    3 different tables as HTML from multiline-table Markdown

4
  • This answer and the one linked are a bit confusing because it says, "yes, relative width columns are possible" then "supported by Pandoc only -- it is a Pandoc-specific extension of Markdown". So really, it seems the answer is "no, relative width columns are not possible without using an extension". Jan 3, 2017 at 1:50
  • Just wanted to point it out since this post is the #1 result for "markdown table column width" in Google and many people visiting are trying to solve the problem for GFM. (Which it doesn't seem there is a solution for.) Jan 3, 2017 at 17:25
  • @TaylorD.Edmiston: So after having read+understood my answer, they'll know that it won't work for GFM. Jan 3, 2017 at 17:30
  • 1
    Sure, I'm just trying to save other people the time of reading two answers, then inferring, then reading comments. It seems more efficient if the point were made up front and explicit. Jan 3, 2017 at 17:35
4

Using CuteMarkEd I could do it with just adding non breaking space to a field in the header raw or in a cell ( ) several time.

1
  • Thx Newuser! This worked for me. Also, the width of the text (including  ) controls the width of the column.
    – dougB
    Nov 22, 2019 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.