用latex3
的循环语法练习了一下,基本上大大缩短了你的代码长度(大概缩了一半吧...)
遇到比较大的问题是tabularray
的expand
展开选项在遇到l3
时有点不好处理...
非常感谢鱼先生 @u19850 给出的使用\expandafter
方法展开拼接字符串的方法,同时也感谢外国友人Ulrike Fischer提供的莫大帮助和提示
% trick to concat the items
\def\mycontent{}
\expandafter\def\expandafter\mycontent\expandafter{
\mycontent
<codes want to put together>
}
下面是缩行成功的MWE:
\documentclass[twoside]{book}
\usepackage[
letterpaper,
bindingoffset=15mm,
textheight=250mm,
textwidth=175mm,
top=1in,
bottom=20mm,
footskip=0.5in,
marginparwidth=0mm,
marginparsep=0mm,
margin = .6in
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{kpfonts}
\usepackage{tabularray}
\pagestyle{plain}
\raggedright
\raggedbottom
\begin{document}
\ExplSyntaxOn
\clist_const:Nn \c_wwws_clist { What, Who, How, When, Where, Why }
\clist_const:Nn \c_questions_clist {
{What~do~I~want~to~achieve?},
{Who~benefits?~Whose~help~do~I~need?},
{Which~skills~do~I~need?},
{What~is~my~timeline?},
{Where~will~I~accomplish~this?},
{Why~is~this~goal~important~to~me?}
}
\clist_const:Nn \c_goals_clist {
{Annual~Goal},
{Monthly~Sub-Goals~for~Annual~Goal},
}
\int_step_inline:nn {7}
{
\int_step_inline:nn {2}
{
\newpage
\begin{center}
{
\Large \textbf{{\clist_item:Nn \c_goals_clist {##1}}~\#~#1~}
}
\end{center}
\vspace{5mm}
\noindent
\def\mycontent{}
\int_step_inline:nn {6}
{
%迭代合并\mycontent内容的trick
\int_compare:nTF{##1=1}{
\expandafter\def\expandafter\mycontent\expandafter{
\mycontent
\SetCell[r=4]{c}{\clist_item:Nn \c_wwws_clist {####1}} & {\clist_item:Nn \c_questions_clist {####1}} \\
& \\ & \\ & \\
}
}{
\expandafter\def\expandafter\mycontent\expandafter{
\mycontent
\SetCell[r=4]{c}{Sub-Goal\\~\#~####1} & {} \\
& \\ & \\ & \\
}
}
}
\begin{tblr}[expand=\mycontent]{
width=175mm,
colspec={ X[1,c] X[8,l] },
vlines,hlines,
rows={7mm, m, rowsep=1.0pt},
font=\bfseries,
}
\mycontent
\end{tblr}
\newpage
}
}
\ExplSyntaxOff
\end{document}
效果如下:
另外,需要注意的是:
- 你的MWE不够Minimal,应该尽可能删除其他无关代码以减少回答者的阅读量
- 这里是列表文本同时表述应清晰,避免使用“后面这几行”来指代. 遇到这种情况更好的处理方法是,分别提供两个
.tex
文件,并且说明是在forloop
中插入第二个tblr
会导致\item
错误 - 论坛的
label
(标签)应尽量是<package name>
,<keyword of your question>
等对问题有概括性/便于分类的tag
,请问下这个文件为啥去掉后面这几行能运行
有这几行就会报错呢
把后面这几行拿出来又能运行
这些label
非常不搭.
问 请问下这个文件为啥去掉后面这几行能运行,有这几行就会报错呢,把后面这几行拿出来又能运行