[Tugindia] Using conditionals
Nina Mazumdar
nina.mazumdar at gmail.com
Sun Sep 14 05:41:05 CEST 2008
On Sat, Sep 13, 2008 at 11:12 PM, Kannan Moudgalya <kannan at iitb.ac.in> wrote:
> Hi,
>
> I want to know how to use the conditionals in LaTeX. For example, if I
> have the \multicols option on, I want the width of the inserted figures
> to be \linewidth. If this option is off, the width should become
> 0.5\linewidth.
Do we need to go for any conditional command? What we need is nothing
but a new dimension defined which is exactly the column width.
Here is one way of doing it:
%---------------- Begin --------------------
\documentclass{article}
\usepackage[english]{babel} % for blindtext
\usepackage{blindtext} % to fill arbitrary text in a document
\usepackage{graphicx}
\usepackage{multicol}
\makeatletter
\newdimen\Columnwidth
\Columnwidth=\textwidth
\advance\Columnwidth by -\columnsep
\divide\Columnwidth by 2
\def\Includegraphics{\@ifnextchar[{\@Includegraphics}{\@Includegraphics[]}}
\def\@Includegraphics[#1]#2{\noindent
\includegraphics[#1,width=\Columnwidth]{#2}}
%
% you can use any of the \includegraphics options too
%
\makeatother
\begin{document}
\begin{multicols}{2}
\blindtext[1]
\Includegraphics{gr}
\end{multicols}
\blindtext[1]
\Includegraphics{gr}
\end{document}
%---------------- End --------------------
Happy TeXing and best regards
--
Nina
More information about the tugindia
mailing list