7

I'm using supertabular in multicols enviroment using this trick

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

I'd like to put that code into \newcommand - I've tried this:

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

but when i use my \newcommand it doesn't work - table is in only one column. What is the right way to define this command?

EDIT: examples

this works fine but i generate multiple multicols in the document so I want to put that trick code into single line comand

\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}

and this doesn't work

\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 Answers1

14

This works.

\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} 

You have to put \makeatother and \makeatletter outside the macro definition.

egreg
  • 1,121,712
  • Oh it really works, i've tried that as you suggested in comment but i must have made some mistake – CGH Tompkins Mar 28 '13 at 17:44
  • Quite impressive and very useful, but I have some issues with long text. The second column overlaps on the first one. The text does not seem to break and go on a new line. I put a MWE here if you are able to take a look. – Lalylulelo Feb 12 '20 at 16:10
  • @Lalylulelo Text in l columns doesn't break across lines. By the way, you'd need very large text width to accommodate three columns. – egreg Feb 12 '20 at 16:21