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} 
4
  • \makeatletter and \makeatother should go as the first and last line respectively (outside the definition of \TrickSupertabularIntoMulticols). Also \let\mcnewpage\newpage should go outside, but it's not as relevant.
    – egreg
    Mar 28, 2013 at 16:21
  • That didn't help
    – Abdul
    Mar 28, 2013 at 16:43
  • A minimal working example (MWE) (also non working, actually) is needed.
    – egreg
    Mar 28, 2013 at 16:53
  • I'm trying to use the first code that you have added. When I add it above my supertabular that starts in the middle of page 18, resulting file stops at page 17. Any idea about this? Jul 9, 2018 at 12:48

1 Answer 1

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.

3
  • Oh it really works, i've tried that as you suggested in comment but i must have made some mistake
    – Abdul
    Mar 28, 2013 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, 2020 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, 2020 at 16:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .