宏改变输出

宏改变输出

下面显示的代码和输出基于以下问题的答案这个帖子

问题是,三个表中的第一个按预期生成,但第二个和第三个表中的第二列垂直居中,这是不理想的。尽管这三个表除了第二个和第三个表中使用宏来减少冗余之外都相同。不知何故,这些宏的引入改变了输出。发生了什么?我该如何解决这个问题?

\documentclass{article}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{tabu}
\usepackage[table]{xcolor}

\begin{document}

This table just repeats all the required commands
for each row.  The output appears as desired.

\begin{center}\small
\setlength{\columnseprule}{.4pt}
\renewcommand\columnseprulecolor{\color{blue}}
\begin{multicols}{2}

\begin{tabu} {>{\bfseries}lX}
\savetabu{mytabu}
Name1 & Value1. \\
\tabucline[blue]-
\end{tabu}

\begin{tabu} {\usetabu{mytabu}}
Name2 & Value2. \\
\tabucline[blue]-
\end{tabu}

\begin{tabu} {\usetabu{mytabu}}
Name3 & Value3. \\
\tabucline[blue]-
\end{tabu}

\end{multicols}
\end{center}

This table uses the RowA macro defined using a \LaTeX{} macro.  The second
column of the table is vertically centered which is not desirable.

\newcommand{\RowA}[1]{
    \begin{tabu}{\usetabu{mytabu}}
    #1 \\
    \tabucline[blue]-\end{tabu}
}

\begin{center}\small
\setlength{\columnseprule}{.4pt}
\renewcommand\columnseprulecolor{\color{blue}}
\begin{multicols}{2}
\raggedcolumns

\begin{tabu} {>{\bfseries}lX}\savetabu{mytabu}
Name1 & Value1. \\
\tabucline[blue]-
\end{tabu}

\RowA{Name2 & Value2.}

\RowA{Name3 & Value3.}

\end{multicols}
\end{center}

This table uses the RowB macro defined using a \TeX{} macro.  The second
column of the table is vertically centered which is not desirable.

\def\RowB#1{
\begin{tabu} {\usetabu{mytabu}}
#1 \\
\tabucline[blue]-\end{tabu}
}
\begin{center}\small
\setlength{\columnseprule}{.4pt}
\renewcommand\columnseprulecolor{\color{blue}}
\begin{multicols}{2}
\raggedcolumns

\begin{tabu} {>{\bfseries}lX}\savetabu{mytabu}
Name1 & Value1. \\
\tabucline[blue]-
\end{tabu}

\RowB{Name2 & Value2.}

\RowB{Name3 & Value3.}

\end{multicols}
\end{center}

\end{document}

截屏

答案1

大部分 TeX 问题的标准答案:

%行末缺失.....

\newcommand{\RowA}[1]{%
    \begin{tabu}{\usetabu{mytabu}}%
    #1\\%
    \tabucline[blue]-\end{tabu}%
}


\def\RowB#1{%
\begin{tabu} {\usetabu{mytabu}}%
#1\\%
\tabucline[blue]-\end{tabu}%
}

相关内容