我是 Latex 新手,对编写 Latex 宏知之甚少。我有数百个要合并到文档中的表格。在每个表中,我需要让某些行以斜体显示,并将非空列值放在括号中。借助本论坛中的许多帖子,我能够将行设为斜体。我被第二部分难住了。使用 Latex 宏的最佳方法是什么?以下是 MWE 复制的问题...
\documentclass[]{article}
\usepackage{longtable,booktabs}
\usepackage{array}
\newcolumntype{+}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\DeclareMathSizes{12}{12}{6}{6}
\begin{document}
\begin{longtable}[c]{ +r^r^r }
\toprule\addlinespace
$\alpha$ & $\beta_1$ & $\beta_2$
\\\addlinespace
\midrule\endhead
0.00057 & -0.42643 & 0.02243
\\
\rowstyle{\itshape}
3.57 & -2.00 &
\\\addlinespace
0.11157 & -0.42 & 0.025
\\
\rowstyle{\itshape}
4.87 & & 7.00
\\\addlinespace
\bottomrule
\addlinespace
\caption{Sample Output}
\end{longtable}
Desired output (Added parenthesis manually)
\begin{longtable}[c]{ +r^r^r }
\toprule\addlinespace
$\alpha$ & $\beta_1$ & $\beta_2$
\\\addlinespace
\midrule\endhead
0.00057 & -0.42643 & 0.02243
\\
\rowstyle{\itshape}
(3.57) & (-2.00) &
\\\addlinespace
0.11157 & -0.42 & 0.025
\\
\rowstyle{\itshape}
(4.87) & & (7.00)
\\\addlinespace
\bottomrule
\addlinespace
\caption{Sample Output}
\end{longtable}
\end{document}
答案1
你可以尝试这个宏\mytable
:
\def\tabrule{\noalign{\medskip\hrule\medskip}}
\def\normaltabitem#1{\ \hfil$#1$\ }
\def\specialtabitem#1{\ \hfil\def\tmp{#1}%
\ifx\tmp\empty\hfil\else(${\it#1}$)\fi\ }
\let\tabitem=\normaltabitem
\def\specrow{\noalign{\global\let\tabitem=\specialtabitem}}
\def\mytable#1{\halign{\tabitem{##}&\tabitem{##}&\tabitem{##}%
\global\let\tabitem=\normaltabitem \cr #1\crcr}}
\mytable{
\tabrule
\alpha & \beta_1 & \beta_2 \cr
\tabrule
0.00057 & -0.42643 & 0.02243 \cr
\specrow 3.57 & -2.00 & \cr
0.11157 & -0.42 & 0.025 \cr
\specrow 4.87 & & 7.00 \cr
\tabrule
}