我想\hline
在此代码的宏扩展中添加一个,这是 David Carlisle 对以下问题的回答的最低限度的修改版本:编译期间生成 LaTeX 表格代码。
用 编译此代码latexmk -pdf main.tex
可得到一个漂亮的表格。我能够通过在 中添加 和 来添加到生成大多数行的宏的宏扩展中。我也能够通过在同一个文件中添加 来添加到代码的开头。但我无法找出如何生成此数组的第一行和第二行。它必须在 中或在 中。那么\hline
如何将添加到用于创建此数组第一行的宏扩展中?\def\hardline{\hline}
\expandafter\hardline
\def\xlistbody
g_orig_dest_tabular1_def.tex
\hline
\noexpand\hline
\def\tablestart
\hline
tabular
\def\listheadings
\def\xlistheadings
g_orig_dest_tabular1_def.tex
\hline
tabular
谢谢 :)
主要.tex:
\documentclass[12pt]{article}
\usepackage[american]{babel}
\usepackage{graphicx}
\input{g_orig_dest_tabular1_def}
\begin{document}
\input{g_orig_dest_tabular1}
\end{document}
g_orig_dest_tabular1_def.tex:
\newcommand\connorigdestregionlist{ABC,DEF,GHI}
% hardline.
\def\hardline{\hline}
% listheadings.
\def\listheadings{%
\expandafter\xlistheadings\connorigdestregionlist,\relax,}
% xlistheadings.
\def\xlistheadings#1,{%
\ifx\relax#1%
\expandafter\\
\else
&\textbf{#1}%
\expandafter\xlistheadings
\fi}
% listbody.
\def\listbody{%
\expandafter\xlistbody\connorigdestregionlist,\relax,}
% xlistbody.
\def\xlistbody#1,{%
\ifx\relax#1%
\else
\textbf{#1}%
\gdef\thisrow{#1}%
\expandafter\xlistdata\connorigdestregionlist,\relax,%
\expandafter\hardline
\expandafter\xlistbody
\fi}
% xlistdata.
\def\xlistdata#1,{%
\ifx\relax#1%
\expandafter\\
\else
&\csname CONNorig\thisrow dest#1\endcsname
\expandafter\xlistdata
\fi}
% preamble.
\def\preamble{\expandafter\xpreamble\connorigdestregionlist,\relax,}
\def\xpreamble#1,{%
\ifx\relax#1%
\else
c%
\expandafter\xpreamble
\fi}
% tablestart.
\def\tablestart{%
\edef\temp{\noexpand\begin{tabular}{c\preamble}\noexpand\hline}%
\temp}
g_orig_dest_tabular1.tex:
\input{g_orig_dest_conn_def}
\tiny
\begin{table}
\scalebox{0.6}{
\tablestart
\listheadings
\listbody
\end{tabular}
} % end scalebox
\caption{Caption goes here.}
\begin{enumerate}
\item Item number one.
\item Item number two.
\end{enumerate}
\end{table}
\normalsize
g_orig_dest_conn_def.tex:
\def\CONNorigABCdestABC{ NA }
\def\CONNorigABCdestDEF{ from ABC to DEF }
\def\CONNorigABCdestGHI{ from ABC to GHI }
\def\CONNorigDEFdestABC{ from DEF to ABC }
\def\CONNorigDEFdestDEF{ NA }
\def\CONNorigDEFdestGHI{ from DEF to GHI }
\def\CONNorigGHIdestABC{ from GHI to ABC }
\def\CONNorigGHIdestDEF{ from GHI to DEF }
\def\CONNorigGHIdestGHI{ NA }
答案1
要获得 hline,您可以更改命令\xlistheadings
或\listheadings
修改\xlistheadings
:
\def\xlistheadings#1,{%
\ifx\relax#1%
\expandafter\\\hline
\else &\textbf{#1}%
\expandafter\xlistheadings
\fi}
修改\listheadings
\def\listheadings{%
\expandafter\xlistheadings\connorigdestregionlist,\relax,\hline}
选择您喜欢的方式。