How to align multiline values in AsciiDoc table?

4k views Asked by At

I would like to dynamically generate a table with asciidoc, which could look like this :

--------------------------------------
|Text  | Parameter | Value1 | Value2 |
--------------------------------------
|foo   | param1    | val1   | val2   |
--------------------------------------
|bar   | param2    | val3   | val4   |
|      | param3    | value_ | val6   |
|      |           | multi_ |        |
|      |           | 5      |        |
|      | param4    | val7   | val8   |
--------------------------------------
| baz  | param5    | val9   | val10  |
--------------------------------------

That is, there might be multiple parameters to one text, and their values might span multiple lines. I am looking for a way to automatically align these. I have a program that gathers data which changes, so I can not manually fix things.

What I currently do: I have frame and gridless nested tables in the Parameter, Value1 and Value2 columns. The problem with this is they only align if each value does not span multiple lines.

I also tried making Parameter, Value1 and Value2 a nested table together, with grid but no frame.

It works in terms of alignment, but doesn't look very good because the grid lines do not touch the gridlines of the outer table. Adding a frame also looks dull since it emphasizes multiparameter entries.

What I really want to do is add an extra line to the outer table (no table nesting) with no horizontal line in between, if there is an extra parameter.

I can not see how to do this with AsciiDoc. Is that possible at all? Any other suggestions on how to solve this?

2

There are 2 answers

0
Isaac On BEST ANSWER

It turns out this is rather easy with spans (see chapter 23.5):

.Multiline values alined with spans
[cols=",,,",width="60%", options="header"]
|================
|Text  | Parameter | Value1 | Value2
|foo   | param1    | val1   | val2
.3+<.<|foo .3+<.<|bar | val3 | val4
| razzle bla fasel foo bar | dazzle
|bli | bla
|foo2   | param3    | val5   | val6
|================

Now all I need to do is tell my templating system (jinja2) how much rows I need to span, but that is rather a diligent but routine piece of work.

1
LightGuard On

If you're using asciidoctor, there are many other options for tables including putting columns on new lines and using the metadata for the table to specify how many columns the table contains. This is the recommended way of doing tables in Asciidoctor. You can see this example and many others in the user's guide. To give an example here on SO:

[cols="2*"]
|===

|Cell in column 1, row 1
|Cell in column 2, row 1

|Cell in column 1, row 2
|Cell in column 2, row 2

|===

Asciidoctor can be a drop in replacement for the asciidoc command, though you will want to look at differences between the two.