![LuaLatex:创建具有多个目录的 tabularx](https://linux22.com/image/458922/LuaLatex%EF%BC%9A%E5%88%9B%E5%BB%BA%E5%85%B7%E6%9C%89%E5%A4%9A%E4%B8%AA%E7%9B%AE%E5%BD%95%E7%9A%84%20tabularx.png)
我正在使用 LuaLatex 创建表格,但只有当整个表格在单个表格内创建时它才有效directlua
。
为什么前者有效而后者无效?
这项工作
\directlua{
tex.print("\\begin{tabularx}{\\linewidth}{XX}")
tex.print("a&b \\\\")
tex.print("\\end{tabularx}")
}
这不
\directlua{
tex.print("\\begin{tabularx}{\\linewidth}{XX}")
tex.print("a&b \\\\")
}
\directlua{
tex.print("\\end{tabularx}")
}
错误消息
Runaway argument?
./main.tex, 7
{XX} a&b \\ \directlua { tex.print("\\end{tabularx}") }
! File ended while scanning use of \TX@get@body.
<inserted text>
\par
l.7 \input{data/Attributes.tex}
I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.
```
答案1
tabularx
提前读取 find\end{tabularx}
以保存表体以供多次试验,但尚未完成。如果没有 lua,您会看到相同的结果,但是
\def\xxx{\end{tabularx}} \begin{tabularx}{\textwidth}... \xxx
因此,您可以使用多个\directlua
但保留 Lua 端的字符串,直到准备好\end
:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{center}
\directlua{
nextbegin="\\begin{tabularx}{\\linewidth}{XX}"
nextbody="a&b \\\\"
}
\directlua{
tex.print(nextbegin)
tex.print(nextbody)
tex.print("\\end{tabularx}")
}
\end{center}
\end{document}