Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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} 
share|improve this question
    
\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 '13 at 16:21
    
That didn't help –  Abdul Mar 28 '13 at 16:43
    
A minimal working example (MWE) (also non working, actually) is needed. –  egreg Mar 28 '13 at 16:53
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Oh it really works, i've tried that as you suggested in comment but i must have made some mistake –  Abdul Mar 28 '13 at 17:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.