尝试创建一个mcqimg
带有参数的新命令,例如\mcqfour
左侧带有图像,右侧带有选项multicolumn
,但无法正常工作。[参考:img1]。任何建议或指导都非常好,我是 LaTeX 新手,最近才开始学习,所以请考虑给我一些详细信息。参考图片:
![参考][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}```
答案1
定义了一个\AskQuestion
包含 5 个参数的命令。问题将自动编号,并将 unique label
添加到问题中以供将来参考。(参见最后两行)。
\AskQuestion{<text of the question>}{<width of the image>}{<image file>}{<first option>, <second option>, <third option>, <fourth option>, <...>}{<unique label>}
第四个参数是回答问题的可变数量的选项,用逗号分隔。(来自具有可变项目数的逐项列举命令)
该命令通过并排使用两个小页面来工作。仅使用图形的宽度,因为人们通常希望保持图像的纵横比。
该enumitem
包有助于格式化四个选项的列表。
\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}