-1

Trying to create a new command called mcqimg with parameters like \mcqfour with image on the left and options on the right using multicolumn but it didn't work properly. [reference: img1]. Any suggestions or guidance will be wonderful, I'm new to LaTeX, recently started learning so please consider giving me a bit of details. Image for Refernce:

reference image ![reference][1]

\RequirePackage[utf8]{inputenc}
\RequirePackage{multicol}
\RequirePackage{ragged2e}
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}

\title{Question Paper}
\author{LB2}
\date{Feb 2022}

\newcommand{\img}[4]{
    \begin{figure}[h]
        \centering
        \includegraphics[ width = #1, height = #2]{#3}

        \label{#4}
    \end{figure}
}

\newcommand{\mcqfour}[7]{
\vspace{2.5mm}
\begin{raggedright}
\textbf{Question #1:} #2 \\
#7
(a) #3\\
(b) #4\\
(c) #5\\
(d) #6\\
\end{raggedright}}

\begin{document}

\mcqfour{1}{Find the area of the figure by splitting the rectangles.}
{190 cm²}
{198 cm²}
{197 cm²}
{203 cm²}
{\img{8cm}{4cm}{q15.jpg}{}{}}

\end{document}```
2
  • Muticol does not support floats, even if you try to hide them. Try using a minipage and \captionof{figure}{...} instead. Also, \label will do no good without a \caption to set \@currentlabel. Feb 26, 2022 at 16:24
  • You might find tex.stackexchange.com/questions/530084/… useful. Feb 26, 2022 at 16:32

1 Answer 1

1

An \AskQuestion command with 5 parameters was defined. The question will be automatically numbered and the unique label will be added to the question for future reference. (See the two last lines).

\AskQuestion{<text of the question>}{<width of the image>}{<image file>}{<first option>, <second option>, <third option>, <fourth option>, <...>}{<unique label>}

The fourth parameter is a variable number of options to answer the question separated by commas. (From Itemize command with variable number of items)

The command works by using two minipages side by side. Only the width of the figure is used because one usually wants to keep the aspect ratio of the image.

The enumitem package helps to format the list of four options.

b

\documentclass[12pt,a4paper]{article}
\RequirePackage[utf8]{inputenc}
\RequirePackage{multicol}
\RequirePackage{ragged2e}
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}   

\title{Question Paper}
\author{LB2}
\date{Feb 2022}

%**************************************************************** added <<<<<<<<<<<<<
\usepackage{enumitem}% 
\usepackage{xparse}

\newcounter{Nquestion}  
\newcommand{\AskQuestion}[5]{%  
\setLabel{#5}
\noindent \textbf{Question \theNquestion:}\ #1\par% 
\medskip
\begin{minipage}{0.65\linewidth}
\includegraphics[ width = #2, keepaspectratio]{#3}
\end{minipage}\hfill
\begin{minipage}{0.30\linewidth}
\VarItemize{#4}
\end{minipage}
\vspace{20pt}   
}
\newcommand{\setLabel}[1]{\refstepcounter{Nquestion}\label{#1}}

% From https://tex.stackexchange.com/questions/503307/itemize-command-with-variable-number-of-items
\ExplSyntaxOn       
\seq_new:N \l__ryanj_tmp_seq        
\cs_new_protected:Npn \ryanj_output_items:n #1
{   \seq_set_from_clist:Nn \l__ryanj_tmp_seq {#1}
    \seq_use:Nn \l__ryanj_tmp_seq { \item }
}

\NewDocumentCommand  \VarItemize { m }
{\begin{enumerate}[itemsep=-0.2ex,label=(\emph{\alph*})]
        \item
        \ryanj_output_items:n {#1}
    \end{enumerate}
}
\ExplSyntaxOff

%****************************************************************

\begin{document}
    
\AskQuestion{Find the area of the figure by splitting the rectangles.}{7cm}{example-image-a}{190 cm², 198 cm², 197 cm², 203 cm²}{q:area}

\AskQuestion{Identify the Kingdom.}{7cm}{example-image-b}{Eubacteria, Archaebacteria, Protozoa, Plantae, Fungi, Animalia}{q:king}   
    
How did you solve the question~\ref{q:area}?
    
What source did you use to answer the question~\ref{q:king}?
    
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .