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'd like to call multicols with a parameter being the number of column and allow this parameter to take the value 1, like in this minimal working example :

\documentclass[a4paper,10pt]{report}
\usepackage{multicol,lipsum}

\newcommand{\varcols}[1]{%
\ifnum#1=1\lipsum\else{\begin{multicols}{#1}\lipsum\end{multicols}}\fi
}

\begin{document}
\varcols{3} 
\end{document}

but the problem is that it forces me to write my text (here \lipsum) two times, which is of course not desirable.

I tried another solution, but unfortunately without success :

\newcommand{\varcols}[1]{%
\ifnum#1=1\relax\else{\begin{multicols}{#1}}\fi
\lipsum
\ifnum#1=1\relax\else{\end{multicols}}\fi
}

but this fails : !Extra }, or forgotten \endgroup.

share|improve this question

closed as too localized by lockstep, cgnieder, Stefan Kottwitz Oct 18 '12 at 21:00

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 4 down vote accepted

Your \else code is

{\begin{multicols}{#1}}

with spurious brace group around the begin. You just want

\begin{multicols}{#1}

and similarly for the end case,

share|improve this answer
    
thank you ! i fell so dumb .. –  Cristo Oct 18 '12 at 17:17

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