我正在移植我的原始 Latex 文件以包含 Lualatex 代码,因为我正在读取输入 JSON 文件。我无法让“resizebox”与 luacode 一起工作,没有它我的表格就会显示出来,但我希望表格与文本宽度对齐,就像在我的原始 tex 文件中一样。有什么线索吗?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}
\usepackage[nohead,paperheight=11.0in,paperwidth=8.5in,left=0.5in,right=0.5in,top=0.5in,bottom=1.0in]{geometry}
%%%%% 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}
\usetikzlibrary{shapes.symbols,shapes.geometric,shadows,arrows.meta}
\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}
投影.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}
投影.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")
tab = json.parse(file:read("*all"))
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}
茶几:
答案1
看起来您希望创建一个表格,其总宽度等于\textwidth
,并且有两个等宽的列,这两个列都应该允许自动换行。如果这个解释是正确的,则\resizebox
、c
列类型和\multicolumn
说明都是多余的和/或无关的。只需加载tabularx
包并使用其同名环境即可。
哦,请不要使用全大写的术语 - 除非您想表现得像想对读者大喊大叫。
\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}