0

While trying to dynamically render a table, it gets out of the document generated and looks as follows:

enter image description here

To avoid this, I followed the steps mentioned in:

But for both the approaches tried, I get an error saying:

Missing number, treated as zero

I tried reading about this error but could not understand, as it does not throw any error when doing without tabularx or adjustbox.

I am rendering my table using lualatex code as shown below:

 tex.print("\string\\begin{tabularx}{"  .. col_schema ..  "}") 

 -- row / col rendering here

 tex.print("\string\\end{tabularx}")

The document is generated from the JSON. I have shared JSON with the link for easier viewing : https://codebeautify.org/jsonviewer/cbe2bd65

What could I do to avoid this error?

Amanda
  • 387

1 Answers1

1

The problem is in

tex.print("\string\\begin{tabularx}{"  .. col_schema ..  "}")

This generates TeX code like

\begin{tabularx}{ | l | l|}

which misses a parameter: The tabularx environment expects the total width as first parameter, like

\begin{tabularx}{5cm}{ | X | X|}

Also this uses X, a column type for automatically sized columns. This type is the main feature of tabularx, so if you do not want to use it for your table, a normal tabular is a better choice.

So there are two possible fixes: Decide for a width and pass it to tabularx, additionally replace at least one column by a X column or replace tabularx with tabular. With tabular, you do not need to pass a width, TeX automatically uses the natural width of your table.

  • Okay. Is there a way to auto-tune the width parameter? With 5cm, I get table that looks as https://ibb.co/Ld3SVsy – Amanda May 08 '19 at 18:11
  • @Amanda As Ulrike Fischer mentioned, you shouldn't use tabularx if you do want to set the table width. If you do want to set the width, but do not want to write an explicit number, you can e.g. use \linewidth to set the width to the width of the current line. – Marcel Krüger May 08 '19 at 18:15
  • @MarcelKrüger: tabularx will only work correctly if one uses at least one X type column. In your answer, the table uses two l type columns instead. – leandriis May 08 '19 at 18:33