Table column sizes

Hi,

Is there any way to control the relative column widths of a Scrivener table compiled to Markdown?

Lyndon

There isn’t a direct way of doing so with the Markdown syntax itself (otherwise we’d probably output that with the table conversion option). However, depending on what format(s) you are looking to output, there may be ways of effectively doing so. Given that the solution is format-dependent, it would help to know what type of document you are looking to produce.

I’m using pandoc to convert the compiled Markdown into two formats: LaTeX and Docx (I use pandoc rather than Scrivener’s Docx compilation mainly to get citation processing).

If I were writing the Markdown directly, I would use the pipe tables syntax that Pandoc recognises for column widths, namely that instead of this from Scrivener’s output:

| :----- | :----- | -----: | -----: |

I would want something like this:

| :- | :---------- | ----------: | -: |

Which pandoc recognises as narrow left-most and right-most columns and wide middle columns.

I should add that in my use of pandoc, I have found that almost every column width I could want can be expressed as 20ths, i.e. this could be achieved by assuming that the full width of a table is composed of 40 colons/dashes in total, to be allocated proportionally by Scrivener considering the relative widths of the columns.

Got it, so you’re using Scrivener’s table conversion option I take it? If so, it doesn’t make use of Pandoc’s mechanisms for doing this, and so your best bet is to stick with adding the pipe tables yourself instead of using the table tool.

I do use the table conversion for some things, where it works to my advantage, and other times I use pipe tables directly where that is a better solution. It’s nice to be able to use both, or to even use the conversion initially for the bulk data entry, convert it to pipes, and then delete the original and paste the pipe table in for tweaking (and to be honest, a more stable result, as table editing can get a bit fragile with the simple tools we have available in the text system).

You don’t have to compile to do that, by the way: just insert the table normally, fill it out, then select it in entirety and use the Copy ▸ Copy Special ▸ Copy as Markdown menu command, and paste over it.

Now that is a cool trick - I hadn’t realised that existed and you’re right, it’s probably the best way to do things.

What I like most about using Scrivener, even though I’m really targeting Pandoc, is that the Styles make it so that I can mostly avoid littering my prose with Markdown markup. There are just a few little wrinkles where that doesn’t work and the Copy as Markdown option certainly helps.

I noticed another little issue with the Markdown compile - it looks like character styles get stripped in the header row (but still work in the body rows). Or at least, the character styles I am using get stripped from the header rows only.

Oh yeah, I’m a big fan of styles, and for that matter section layouts which act as a sort of outline-level style, in that they also have prefix/suffix tabs. You can embed sections into custom LaTeX environments, or Pandoc div classes for docx stylesheet output, etc.

By the way, grab a copy of the official user manual project, and have a look at how I handle table setup in there. This project uses MultiMarkdown → LaTeX, which lacks Pandoc’s control over tables. So what I do is put my custom tabulary line into a special custom metadata field, which the Table section layout injects prior to the table itself as a LaTeX comment. My post-processing script then scans the final .tex file for these marked custom tabulary lines and replaces the vanilla one with it. Using that technique, I am able to lean on the table conversion option for the large majority of the tables in the book. But there are other Markdown-related tricks in that project that you might find useful in your own work, too.

I noticed another little issue with the Markdown compile - it looks like character styles get stripped in the header row (but still work in the body rows). Or at least, the character styles I am using get stripped from the header rows only.

Could you give an example of that one, walking me through the setup and expected output, just to make sure we’re on the same page?

I have a small caps character style, which in the compile format I have so that nrsv gets compiled to [nrsv]{.smallcaps} by adding a prefix and a suffix in the compile format for that character style. This doesn’t work in the header (first) row of the table. The text just gets compiled to nrsv instead. Character styles do seem to be applied (i.e. the prefix and suffix) for text in the body of the table.

And I’ve got a copy of the manual project and will go through it. Thanks for the pointer to it!

I see that, in my web site generated from Scrivener’s rich text tables, columns have an equal width of 50% each.

HTML readers should be able to automatically adjust the column width to the content. Is there a way to output rich tables so that no column width is indicated in the HTML code?

If I understand correctly, if this is not possible, the suggested way is to use Scrivener’s “Copy as Markdown” (or as HTML) command to do this.

Paolo

Isn’t 50% not a width but rather the columns’ share of the available space. ( → Ain’t actually that what you say you want?)

I vaguely remember from designing (by hand) a website that there was a variable (“T” if I remember right) that was the equivalent.

So if a column is alone with its “T” it would take the whole space.
2T = 50 percent each

So you could have a column with “TTT”, one with “T”, and finally one with “TT”
→ 50% – 16% – 34%

A 50% share is not what I want. I want an automatically adaptive width of a table’s columns. In the particular case of my tables, the left column only contains one or a few words, and the right one contains a long explanation. So, it’s more a 20% | 80% share.

This is the HTML code generated by Scrivener → Pandoc → Quarto at the beginning of a table:

<table class="table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>

Paolo

Ok. So you are saying you can’t get them to be 20% - 80% ?
(Different width per column – which is what I understood from the start.)

Perhaps you could fix them afterwards in Sigil (or whatever you use to edit html if it’s for a website), since there is obviously two 50% value, and not only one pertaining to both at once. (?)

image

Else, this :

…is why I mentioned the “T” variable. (I am not even sure it was “T” ; it’s been years… don’t give my answer too much credit.)
Perhaps there is one that would be “elastic” (to say) and that would give you this adaptability you are looking for. Something you’d put afterwards as a replacement for the % of your columns. (?)
(Although I have to say that with my (although limited) experience in html, I have never seen such. It is always either fixed or proportional. – You can set a maximum width for a column, the others will take whatever space it doesn’t grow to.)
(But… what happens to text wrap? If your narrow column has a sentence that’s half the total available space, it all goes down the toilet? – One sentence and you’d have done all this for nothing?)

1 Like

I’m not sure exactly what you are trying to do Paolo, but Quarto at least has a way to specify column widths:

| fruit  | price  |
|--------|--------|
| apple  | 2.05   |
| pear   | 1.37   |
| orange | 3.09   |

: Fruit prices {tbl-colwidths="[75,25]"}

And can even be specified in the metadata: tbl-colwidths: [75,25] — The in-text specification depends on the table legend (: legend here) , and so you can use Scrivener’s styles / Section Types to inject the correct markup, or just add raw markup directly in the editor. The metadata method should apply across the project if you need consistent tables…

1 Like

I want to keep the post-editing at a minimum, since any of these intervention would have to be repeated at each update. I know there is some touch-up to do with VS Code or BBEdit on the code generated by Scrivener, but it has to be just something on a few configuration files. Nothing more, or it would be unmanageable.

Yes, and I fear that making tables all in markdown, at least after the initial heavy-weight lift-up, is the only solution. The fun part is that all the examples on markdown tables are always about single-word elements and number following them. Mine are long explanation that wrap on multiple lines.

This is one of the cases where Scrivener’s rich text authoring would be the most useful. Tables would be as complex as you like, and still be easy to handle.

As for markdown, I’m still trying to understand if I can at least split a table row into separate rows, for ease of reading. Something like this, extending the concept of grid tables:

+---
This is the first column's header
And this is the second column's header, much better than the one you can see here in the left column
This is just a value, in the third column
+===

This is the first parameter
And here we go on and on explaining what it does, and what it would be better you, the inconsiderate user, don't do or touch to avoid messing things up.
100%

This is the second parameter. Anything follows.
...
+---

Maybe I should suggest this to the developer of Pandoc.

Paolo

Yes, and I fear that making tables all in markdown, at least after the initial heavy-weight lift-up, is the only solution.

There is nothing stopping you from mixing tables with the syntax necessary, around them, to describe them. This is not an either/or scenario. Just visualise what Scrivener will be generating, and put your stuff in the right place around it.

That is precisely what I do with the user manual, though there my approach is bespoke rather than using established conventions. My post-processing script takes the table sizing instructions I supply in the compiled output and modifies the tables on the fly. The tables themselves are simple rich text tables in Scrivener. The stuff that makes it look right is in a custom metadata field over in the inspector. But if I didn’t want to get fancy about it, I could just have the sizing instructions in the text editor too, above the table.

Again, I think it is useful to visualise the .md file Scrivener creates, when looking at the stuff it can do to generate syntax for us. We can use its footnote feature and type asterisks around text within the inspector sidebar to denote emphasis, all at once. We don’t have to stop using Markdown if we use the footnote feature, and we don’t have to stop using the footnote feature if we want to use asterisks. Scrivener’s great strength is how we can do both simultaneously, and thus reduce our workload where it makes sense to. Manually managing pipe tables is a bore and a waste of time, the software can do that for us. If we need more, we can type the things we need around it.

1 Like

Great hint! I just added this line after the rich text table:

: {tbl-colwidths="[20,80]"}

and got a table with the desired proportions!

Paolo

1 Like

For those who would like to use markdown tables, this web site offers a great visual editor for more complex grid tables that are hard to write manually but offer more features than any other table type (row and column spanning, paragraphs etc.)

You need to enable the Use reStructuredText syntax option. The cool thing is you can make your table, then copy and save it to Scrivener; you can copy it back to that page (File ⇨ Paste table data…) and you can continue editing it:

+-------+-------+--------+--------+------+
| Jane  | John  | Joanna | Robert | Paul |
+=======+=======+========+========+======+
| a     | b     | c      | d      | e    |
+-------+-------+--------+--------+------+
| f     | g     | h      | we are | i    |
+-------+-------+--------+ merged +------+
| we are merged | l      |        | m    |
+---------------+--------+--------+------+

This will only work with a Pandoc-based compiler workflow…

IIRC @KB did say that he had worked on a better table system, and perhaps with Scrivener 4 we will have something that better supports these customisations (as at least pandoc supports custom column widths, wrapping, row & column spans etc.)

4 Likes

I’ve been using that site for text tables lately. I like that I can make a table with Excel and then either copy/paste to that site, or else save the excel table to csv and import to that site. FYI there’s a relevant bug in Pandoc:

2 Likes

Thanks @jpkell for the bug report!

For those who’d like to write a table like a list, there is a really nice pandoc extension, that supports column widths and other features:

:::{.list-table widths=1,3 aligns=l,c header-cols=1}
   * - Name
     - Features

   * - Pandoc Markdown
     - Multiple input + output conversion

   * - LaTeX
     - Precise PDF generation
:::

This is a nice alternative format amenable to quick editing while still allowing a bit of customisability…

2 Likes

Does this lua filter work for docx output? The readme doesn’t seem to mention outputs, and I’m not having success with my docx tests. The great thing about the text-based tables is that they work across outputs.