Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control cell width in a Pandoc/Markdown table?

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.

like image 740
Mustafa Avatar asked Nov 30 '14 23:11

Mustafa


People also ask

How do you reduce cell width in a table?

On the Layout tab, in the Cell Size group, click AutoFit. Do one of the following. To adjust column width automatically, click AutoFit Contents. To adjust table width automatically, click AutoFit Window.

How do I break a line in a table in markdown?

A newline in Markdown is created by “2 spaces at the end of the line and a single newline”. where the _ are spaces.

What is Pandoc R?

pander: An R 'Pandoc' WriterContains some functions catching all messages, 'stdout' and other useful information while evaluating R code and other helpers to return user specified text elements (like: header, paragraph, table, image, lists etc.)


1 Answers

{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

like image 53
Kurt Pfeifle Avatar answered Sep 17 '22 12:09

Kurt Pfeifle