2

enter image description here

See the fourth question: the choices are showing twice one is along horizontal and another is along vertical, but I need only one like the above three. The commands I have used is given below.

\documentclass{exam}
\usepackage{ifthen}
\usepackage{calc}
\renewcommand{\baselinestretch}{1.2}
\oddsidemargin 0in \evensidemargin 0in \topmargin 0in \textheight
9.2in \textwidth 6.5in
%\hoffset -1in
%\voffset -1in
%\evensidemargin 14pt
\usepackage{amsmath,amsthm,amsfonts,amssymb,dsfont}
\pagestyle{headandfoot} \extraheadheight{.5in} \lhead[]{}
\chead[ \vskip .1in  MATHEMATICS\\
STANDARD X(CBSE)\\
      %\hrule
    \textbf{PAIR OF LINEAR EQUATIONS IN TWO VARIABLES} \linebreak
       \textbf{Time: 1 Hour}   \hskip 1.3in  \textsf{ }
       \hfill{\textbf{Max. Marks:30}}\vskip.05in \vskip -.5in]{}
\rhead[]{} \lfoot{David 7502878908} \cfoot{HOME TUITIONS}
\rfoot{\iflastpage{$\maltese\maltese\maltese \maltese
\maltese$}{Continued...\ldots}} \pointsinrightmargin
\newcommand{\ntt}{\normalfont\ttfamily}
%    command name
\newcommand{\cn}[1]{{\protect\ntt\bslash#1}}
\hfuzz1pc % Don't bother to report overfull boxes if overage is < 1pc

\newcommand{\thmref}[1]{Theorem~\ref{#1}}
\newcommand{\secref}[1]{\S\ref{#1}}
\newcommand{\lemref}[1]{Lemma~\ref{#1}}
%\newcommand{\bysame}{\mbox{\rule{3em}{.4pt}}\,}
\newcommand{\sqt}[1]{\sqrt{\smash[b] {#1}}}

%    \interval is used to provide better spacing after a [ that
%    is used as a closing delimiter.
\newcommand{\interval}[1]{\mathinner{#1}}

%    Notation for an expression evaluated at a particular condition. The
%    optional argument can be used to override automatic sizing of the
%    right vert bar, e.g. \eval[\biggr]{...}_{...}
\newcommand{\eval}[2][\right]{\relax
  \ifx#1\right\relax \left.\fi#2#1\rvert}

%    Enclose the argument in vert-bar delimiters:
\newcommand{\envert}[1]{\left\lvert#1\right\rvert}
\let\abs=\envert

%    Enclose the argument in double-vert-bar delimiters:
\newcommand{\enVert}[1]{\left\lVert#1\right\rVert}
\let\norm=\enVert
\newcommand{\pad}[2]{\frac{\der #1}{\der #2}}
\newcommand{\IC}{{\mathbb C}}
\newcommand{\IN}{{\mathbb N}}
\newcommand{\IR}{{\mathbb R}}
\newcommand{\gol}{\mbox{$\,${\rm Log}$\,$}}
\newcommand{\Log}{\ln}
\newcommand{\ov}[1]{\overline{\smash[b] {#1}}}
\newcommand{\Ndash}{\nobreakdash--}
\newcommand{\IE}{{\mathds{R}^n}}
\newcommand{\IF}{{\mathds{R}^m}}
\setlength\parindent{0pt}

    %usage \choice{ }{ }{ }{ }
    %(A)(B)(C)(D)
    \newcommand{\fourch}[4]{
    \par
            \begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
            (a)~#1 & (b)~#2 & (c)~#3 & (d)~#4
            \end{tabular}
    }

    %(A)(B)
    %(C)(D)
    \newcommand{\twoch}[4]{

            \begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
            (A)~#1 & (B)~#2
            \end{tabular}
    \par
            \begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
            (C)~#3 & (D)~#4
            \end{tabular}
    }

    %(A)
    %(B)
    %(C)
    %(D)
    \newcommand{\onech}[4]{
    \par
          (A)~#1 \par (B)~#2 \par (C)~#3 \par (D)~#4
    }

    \newlength\widthcha
    \newlength\widthchb
    \newlength\widthchc
    \newlength\widthchd
    \newlength\widthch
    \newlength\tabmaxwidth

    \setlength\tabmaxwidth{0.96\textwidth}
    \newlength\fourthtabwidth
    \setlength\fourthtabwidth{0.25\textwidth}
    \newlength\halftabwidth
    \setlength\halftabwidth{0.5\textwidth}

    \newcommand{\choice}[4]{
            \settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}
            \settowidth\widthchb{BM.#2}    
            \ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
            \settowidth\widthchb{CM.#3}    
            \ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
            \settowidth\widthchb{DM.#4}    
            \ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}     
            \ifthenelse{\widthch<\fourthtabwidth}{\fourch{#1}{#2}{#3}{#4}}

{\ifthenelse{\widthch<\halftabwidth\and\widthch>\fourthtabwidth}{\twoch{#1}{#2}{#3}{#4}}
                               {\onech{#1}{#2}{#3}{#4}}}
    }


\begin{document}
\hrule
\begin{questions}
        \question What is your favourite color?
    \onech{cjfije}{nkwjfl}{vvkji}{ n ejok}
    \question nci jifj
    \twoch{nknfi}{nvsjijp}{msj8j}{n vuhjkd}
    \question kkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
    \fourch{qqqqqqqqq}{qqqqqqqqqq}{qqqqqqqqq}{rrrrrrrrrrrr}
    \question what is your favourite fruit?
    \choice{apple}{banana}{orang}{pear}
\end{questions}

\end{document}

I think there is a wrong in the following redefinition..

\newcommand{\choice}[4]{
                \settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}
                \settowidth\widthchb{BM.#2}    
                \ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
                \settowidth\widthchb{CM.#3}    
                \ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
                \settowidth\widthchb{DM.#4}    
                \ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}     
                \ifthenelse{\widthch<\fourthtabwidth}{\fourch{#1}{#2}{#3}{#4}}

    {\ifthenelse{\widthch<\halftabwidth\and\widthch>\fourthtabwidth}{\twoch{#1}{#2}{#3}{#4}}
                                   {\onech{#1}{#2}{#3}{#4}}}
        }

Kindly correct it and tell me how to identify the correct choice and to print in a separate sheet.

  • What do you mean by "tell me how to identify the correct choice and to print in a separate sheet"? – Werner Jul 2 '14 at 6:05
  • that is I need to mark the correct choice in my question typing and to be printed at the end of questions... like the text book where one has posted the questions and giving the answers at the back.. @Werner – David Jul 2 '14 at 6:41
2

In order to perform a length test using ifthen you need to explicitly state it:

\ifthenelse{\lengthtest{<dimen>?<dimen>}}{<true>}{<false>}

where ? is one of <, = or >. I've adopted a more old-school way of testing dimensions using \ifdim:

\newcommand{\choice}[4]{%
  \settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}%
  \settowidth\widthchb{BM.#2}%
  \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
  \settowidth\widthchb{CM.#3}%
  \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
  \settowidth\widthchb{DM.#4}%
  \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
  \ifdim\widthch<\fourthtabwidth
    \fourch{#1}{#2}{#3}{#4}
  \else\ifdim\widthch<\halftabwidth
    \ifdim\widthch>\fourthtabwidth
      \twoch{#1}{#2}{#3}{#4}
    \else
      \onech{#1}{#2}{#3}{#4}
    \fi
  \fi\fi
}

enter image description here

  • i need to print the answers at the back... how i can?? – David Jul 2 '14 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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