# Table Resizebox with lualatex

I'm porting my original Latex file to include Lualatex code, as I'm reading an input JSON file. I'm unable to get 'resizebox' to work with luacode, without it my table shows up but I want the table aligned to textwidth like in my original tex file. Any leads pelase? JOSN:

{
"ID":"ProjectionParams",
"tableEntries":{
"PROJECTION":"UNIVERSAL TRANSVERSE MERCATOR (UTM)",
"SEMI-MAJOR":"0",
"INVERSE FLATTENING OF REFERENCE ELLIPSOID":"0",
"SCALE FACTOR ALONG THE CENTRAL MERIDIAN":"0",
"WORLD MAGNETIC MODEL":"0"
}
}


MAIN.Tex

\documentclass[12pt]{article}

\usepackage[document]{ragged2e}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

%%%%% dynamic table package %%%%%
\usepackage{datatool}
\DTLsetseparator{,}% Set the separator between the columns.
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{amsmath}

\usepackage{hhline}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{color, colortbl}
\usepackage[table]{xcolor}
\usepackage{graphicx}

\usepackage{tikz}
\usepackage{float}
\tikzset{>={Latex[width=1.5mm,length=2mm]}}

%conditionals package
\usepackage{xparse}
\usepackage{etoolbox}

\renewcommand{\arraystretch}{1.5}  %cell height
\usepackage{luacode}

\begin{document}
\begin{FlushLeft}
ISOGONIC LINES PROGRAM
\end{FlushLeft}

\input{projection.tex}
\end{document}


projection.tex ( TEX):

\section*{PROJECTION PARAMETERS}
\begin{tikzpicture}
\begin{scope}[yscale=1,xscale=-1,xshift=-7.5in]
\draw (-0.04in,-0.22in) -- (7.54in,-0.27in);
\end{scope}

\end{tikzpicture}

%%% Tex input to table %%%
\begin{table}[H]
\resizebox{\textwidth}{!}{%
\begin{tabular}{cc}

\hline
%row no:1

\multicolumn{1}{|p{3.55in}}{\textbf{PROJECTION}}&
\multicolumn{1}{|p{3.55in}|}{\PROJECTION}\\
\hhline{--}
%row no:2

\multicolumn{1}{|p{3.55in}}{\textbf{SEMI-MAJOR AXIS OF REFERENCE ELLIPSOID (METERS):}} &
\multicolumn{1}{|p{3.55in}|}{\SEMIMAJOR} \\
\hhline{--}
\end{tabular}
}
\end{table}


projection.tex (Lualatex ):

\section*{PROJECTION PARAMETERS}
\begin{tikzpicture}
\begin{scope}[yscale=1,xscale=-1,xshift=-7.5in]
\draw (-0.04in,-0.22in) -- (7.54in,-0.27in);
\end{scope}
\end{tikzpicture}

\begin{luacode}
local json = require("json")
local file = io.open("data.json")
file:close()

tex.print("\\begin{table}[H]")
tex.print("\\resizebox{\textwidth}{!}{%")
tex.print("\\begin{tabular}{|c|c|}")
tex.print("\\hline")

tex.print("{PROJECTION} &")
tex.print(tab["tableEntries"]["PROJECTION"])
tex.print("\\\\ \\hhline{--}")
tex.print("{SEMI-MAJOR AXIS OF REFERENCE ELLIPSOID (METERS)} &")
tex.print(tab["tableEntries"]["SEMI-MAJOR"])
tex.print("\\\\ \\hhline{--}")

tex.print("\\end{tabular}")
tex.print("\\}")
tex.print("\\end{table}")

\end{luacode}


End Table:

• Wouldn't it be easier to make sure both columns ar enarrow enough to fit onto the page in the first place, instead of trying to scale the table, which would in turn lead to inconsistent font sizes? May 10 '21 at 20:01
• using \resizebox with tables should be avoided at all costs, it is bound to produce fonts and rule widths inconsistent with the rest of the document. May 10 '21 at 20:18
• I'd get the table sorted out in tex first the lua code is just obscuring things, for instance why is the tablular using cc and then every cell is usiing \multicolumn to replace that by p ? If your table uses two p columns you know in advance how wide it is, so you can choose a width that fits so no scaling is needed. May 10 '21 at 20:50
• You should fix your example so people can run it and debug the issue. add a small but working json file and make the tex a complete document with \documentclass to \end{document} May 10 '21 at 20:51
• no one can run the code posted or see the problem that you are seeing. Your main.tex has no documentclass for example. the lua seems to be unrelated to your question, it is just writing tex code so you could ask a question just using tex that asks about the table alignment. \resizebox and tabular etc are not handled by the lua code at all, to Lua it is just a string that is written to the tex document to be interpreted as tex. May 10 '21 at 21:14

It looks like you wish to create a table whose overall width is equal to \textwidth and which has two equally wide columns, both of which are supposed to allow automatic line wrapping. If this interpretation is correct, the \resizebox, the c column type, and the \multicolumn instructions are all superfluous and/or extraneous. Just load the tabularx package and use its eponymous environment.

Oh, and PLEASE DON'T USE ALL-CAPS TERMS -- UNLESS YOU WANT TO COME ACROSS AS WANTING TO SHOUT AT YOUR READERS.

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\begin{document}
\section*{Projection parameters}

\begin{table}[ht!]
\begin{tabularx}{\textwidth}{@{} LL @{}}
\hline
\textbf{Projection} & Projection \\
\hline
\textbf{Semi-major axis of reference ellipsoid (meters)} &
Semimajor \\
\hline
\end{tabularx}
\end{table}

\end{document}

• @Mico- also added the end table that I was working to get at in my original post... your example works for me.....my challenge is getting lua to print this to tex so I can read json entries from the input file and dynamically fill the table contents. May 10 '21 at 22:07
• is there a way to create the table rows on the fly on a condition then predefine the number of rows? May 10 '21 at 22:16
• @24suns - for an example of how to use LuaLaTeX to populate the contents of anarray environment programmatically, please see this answer to the query I'm searching for a table with cdf of standard normal distribution. (Shameless-self-citation alert!)
– Mico
May 11 '21 at 8:49