选择题类型设置

选择题类型设置

在此处输入图片描述

参见第四个问题:选项显示了两次,一个是沿水平方向,另一个是沿垂直方向,但我只需要一个,就像上面的三个一样。我使用的命令如下。

\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}

我认为以下重新定义是错误的。

\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}}}
        }

请纠正并告诉我如何识别正确的选择并在单独的纸张上打印。

答案1

为了使用进行长度测试ifthen你需要明确地说明:

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

其中?<=或之一>。我采用了一种更老式的方法来测试维度,即\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
}

在此处输入图片描述

相关内容