You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义带7个参数的LaTeX环境报错求助:非法字符与#号错误

排查LaTeX新环境的两个关键错误

我帮你拆解一下这两个错误的根源,以及对应的修复方案:

1. 错误「Illegal character in array arg.」的原因

这个错误是因为你把文本内容放到了multicolumn的列格式参数位置。

在LaTeX中,\multicolumn{列数}{格式}{内容}的第二个参数必须是表格列的对齐格式(比如c居中、l左对齐、r右对齐,或者带竖线的|c|),但你把#3和#4(也就是你要显示的单词定义文本)直接填到了这个位置。LaTeX会把这段长文本当成列格式来解析,里面的空格、括号、斜杠都是非法的格式字符,自然会报错。

2. 错误「You can't use `macro parameter character #' in restricted horizontal mode.」的原因

这个是第一个错误引发的连锁问题:当LaTeX错误地解析#3的文本为列格式时,文本里的内容触发了对参数符号#的错误调用场景,修正第一个问题后,这个错误会自动消失。

修复后的代码

我调整了multicolumn的参数位置,把固定的列格式(这里用c居中)放在第二个参数位置,把你要显示的文本#3、#4放到内容位置:

\documentclass{article}
\usepackage[margin=1in, a4paper]{geometry}
\usepackage{titlesec}
\usepackage{fontspec}
\usepackage{comment}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{bengali}
\setmainfont{Times New Roman}
\newfontfamily\bengalifont[Script=Bengali]{Kalpurush}

\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother

    
\newenvironment{word}[8]% environment name
{
\begin{tabular}{c c c c c c c}
\fbox{#1} & \textit{#2} & --- & \multicolumn{4}{c}{#3}\\\\
& & & \multicolumn{4}{c}{#4}\\\\
\hline
& & & #5 & #6 & #7 & #8\\\\
\hline
\end{tabular}
}
{}


\title{Words}
\author{}
\date{January 2023}

\begin{document}

\maketitle

\section{11/01/2023}

\begin{word}{654}{respite}{A (temporary) relief from harm or discomfort/A pause for relaxation/The art of reprieving; postpone or remitting punishment}{}{}{}{}{}\end{word}

\end{document}

额外优化建议

  • 如果你的单词定义文本很长,建议把multicolumn的格式改成带固定宽度的段落格式,比如\multicolumn{4}{p{8cm}}{#3},这样文本会自动换行,不会超出页面边界。
  • 可以给表格添加竖线让结构更清晰,比如把列格式改成|c|c|c|c|c|c|c|,或者使用tabularx包来自动适配页面宽度的列。

内容的提问来源于stack exchange,提问作者Fahad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 18:15:36