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


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?

  • 1
    I don't think that tabularx is the right solution, better calculate your width and use p{} columns in a normal tabular. – Ulrike Fischer May 8 '19 at 18:10
  • @UlrikeFischer Could you show how? – Amanda May 8 '19 at 18:12
  • 2
    do not use tabularx especially if you are trying to make it fast and you have lots of them, it resets each table multiple times guessing column widths. If you do you it you need to generate the right syntax as noted in the answer – David Carlisle May 8 '19 at 18:35
  • @DavidCarlisle Could you suggest a better way with an answer? – Amanda May 8 '19 at 18:39
  • @Amanda use \begin{tabular}{p{2cm}p{4cm}p{3cm}} for some suitable column widths, it is your document I can't pick suitable widths – David Carlisle May 8 '19 at 18:41

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.

| improve this answer | |
  • Okay. Is there a way to auto-tune the width parameter? With 5cm, I get table that looks as ibb.co/Ld3SVsy – Amanda May 8 '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 8 '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 8 '19 at 18:33

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.