\documentclass{article}
\usepackage{ifthen}
\newenvironment{fred}{%
\begin{tabular}{lll}
\multicolumn{3}{c}{Hello} \\
\hline
}{%
\hline
\end{tabular}
}
\newboolean{doaline}
\setboolean{doaline}{true}
\newcommand{\aline}[1]{%
\ifthenelse{\boolean{doaline}}{%
\multicolumn{3}{r}{#1} \\
}{}%
}
\begin{document}
\begin{fred}
\aline{There}
\end{fred}
\end{document}
(This is a rather contrived example.)
In this document, I get a "!Misplaced \omit" error in the \aline
invocation. I'm using the TeXLive 4 distribution.
Can anyone tell me what's happening and what I'm doing wrong?
--
Doug Palmer Applied Financial Services
WWW: http://users.orac.net.au/~doug
mail: do...@afs.net.au, dou...@acm.org
>I'm a novice Tex/LaTeX hacker:
>
>\documentclass{article}
>\usepackage{ifthen}
>\newenvironment{fred}{%
> \begin{tabular}{lll}
> \multicolumn{3}{c}{Hello} \\
> \hline
>}{%
> \hline
> \end{tabular}
>}
>\newboolean{doaline}
>\setboolean{doaline}{true}
>\newcommand{\aline}[1]{%
> \ifthenelse{\boolean{doaline}}{%
> \multicolumn{3}{r}{#1} \\
> }{}%
>}
>\begin{document}
>\begin{fred}
>\aline{There}
>\end{fred}
>\end{document}
>
>In this document, I get a "!Misplaced \omit" error in the \aline
>invocation. [...]
>
>Can anyone tell me what's happening and what I'm doing wrong?
\multicolumn is only allowed at the begin of a tabular cell.
There can be macros before, but they have to be full expandible.
That means, they vanish if they are expanded.
But \ifthenelse isn't full expandable, so \multicolumn starts
not at the begin of a new cell and you get the "misplaced \omit"
error.
Solutions:
* Calling of \ifthenelse before the begin of a new cell, at the end
of the previous line for example (not possible in your example).
* Use of plain-TeX switches instead of ifthen-booleans
\newif\ifdoaline
\doalinetrue
\ifdoaline
...
\else
...
\fi
The boolean implementation uses \newif, so you can use the boolean
interface of package ifthen and it is necessary only to replace
\ifthenelse by \ifdoaline...\else...\fi
* \ifdoaline...\else...fi can be hidden in a macro:
\makeatletter
\newcommand*{\ifboolean}[1]{%
\csname if#1\endcsname
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\makeatother
\ifboolean{doaline}{true case}{false case}
Yours sincerely
Heiko <ober...@ruf.uni-freiburg.de>
> * Use of plain-TeX switches instead of ifthen-booleans
This works beautifully. Thankyou.