使用新命令将 Supertabular 转换为 Multicols

使用新命令将 Supertabular 转换为 Multicols

supertabularmulticols环境中使用这个技巧

\let\mcnewpage=\newpage
\makeatletter
\renewcommand\newpage{%
    \if@firstcolumn
        \hrule width\linewidth height0pt
        \columnbreak
    \else
        \mcnewpage
    \fi
}
\makeatother

我想把该代码放入\newcommand-我已经尝试过这个:

\newcommand{\TrickSupertabularIntoMulticols}{
\let\mcnewpage=\newpage
\makeatletter
\renewcommand\newpage{%
    \if@firstcolumn
        \hrule width\linewidth height0pt
        \columnbreak
    \else
        \mcnewpage
    \fi
}
\makeatother
}

但是当我使用时\newcommand它不起作用 - 表格只有一列。定义此命令的正确方法是什么?

编辑:例子

这工作正常,但我在文档中生成了多个多列,所以我想把这个技巧代码放入单行命令中

\documentclass{article}
\usepackage{supertabular,multicol}

\newcount\n
\n=0
\def\tablebody{}
\makeatletter
\loop\ifnum\n<100
        \advance\n by1
        \protected@edef\tablebody{\tablebody
                \textbf{\number\n.}& shortText
                \tabularnewline
        }
\repeat
\makeatother

\begin{document}
\begin{multicols*}{2}
\let\mcnewpage=\newpage
\makeatletter
\renewcommand\newpage{%
        \if@firstcolumn
                \hrule width\linewidth height0pt
                \columnbreak
        \else
                \mcnewpage
        \fi
}
\makeatother

\begin{supertabular}{|l|l|}
\tablebody
\end{supertabular}
\end{multicols*}
\end{document}

但这不管用

\documentclass{article}
\usepackage{supertabular,multicol}

\newcount\n
\n=0
\def\tablebody{}
\makeatletter
\loop\ifnum\n<100
        \advance\n by1
        \protected@edef\tablebody{\tablebody
                \textbf{\number\n.}& shortText
                \tabularnewline
        }
\repeat
\makeatother

\newcommand{\TrickSupertabularIntoMulticols}{
\let\mcnewpage=\newpage
\makeatletter
\renewcommand\newpage{%
        \if@firstcolumn
                \hrule width\linewidth height0pt
                \columnbreak
        \else
                \mcnewpage
        \fi
}
\makeatother
}

\begin{document}
\begin{multicols*}{2}
\TrickSupertabularIntoMulticols
\begin{supertabular}{|l|l|}
\tablebody
\end{supertabular}
\end{multicols*}
\end{document} 

答案1

这有效。

\documentclass{article}
\usepackage{supertabular,multicol}

\newcount\n
\n=0
\def\tablebody{}
\makeatletter
\loop\ifnum\n<100
        \advance\n by1
        \protected@edef\tablebody{\tablebody
                \textbf{\number\n.}& shortText
                \tabularnewline
        }
\repeat

\makeatletter
\let\mcnewpage=\newpage
\newcommand{\TrickSupertabularIntoMulticols}{%
  \renewcommand\newpage{%
    \if@firstcolumn
      \hrule width\linewidth height0pt
      \columnbreak
    \else
      \mcnewpage
    \fi
  }%
}
\makeatother

\begin{document}
\begin{multicols*}{2}
\TrickSupertabularIntoMulticols
\begin{supertabular}{|l|l|}
\tablebody
\end{supertabular}
\end{multicols*}
\end{document} 

您必须将\makeatother\makeatletter放在宏定义之外。

相关内容