3

I am new to LaTeX and trying to compile several questions and answers for a book. I would be using question answer after a certain section or as per choice anywhere in the document.

So, I want the questions & answer to be auto-numbered. the numbering should reset once I use another set of exercise at some other section of the document. My sample design is as provided in the image This is one option that I will use inside the chapter at various sections This option I will be using at the end of the chapter

The MWE may be as follows

%The colour and font size of the text should be customizable as an option red colour to be used for font% %The questions and answers are are grouped together for each question and there are various types of question%

%Please note I already have tcolourbox for labeling and referencing so title exercise 1.1 etc. not needed. I only this this question and answer listing so that I able to use them as where I like. No need to link to any section or chapter % as I already have the colorbox code for that inside which i will put his code.%%

\documentclass[hidelinks,11pt]{book}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{exercise}
\usepackage{xsim}
\usepackage{blindtext}
\usepackage[english]{babel}

\begin{document}



{\noindent \textbf \LARGE  This is one option of one by one question answer}\bigskip

{\noindent \textbf {Question 1.}} Which if the following is a secondary memory Devices.?\hfill \break  
    (a) keyboard    (b) Monitor (c) Hard Disk   (d) SMPS \hfill \break          
{\textbf {Answer 1.}} (c) Hard Disk.     \vspace{2\baselineskip} %used for skiping line for next question visibility

{\noindent \textbf {Question 2.}} Recently deleted files are stored in\hfill \break           
    (a) Recycle bin (b) Taskbar (c) My computer (d) desktop \hfill \break       
{\textbf {Answer 2.}} ( a) Recycle bin.      \vspace{2\baselineskip}

{ \noindent \textbf {Question 3.}} What is RAM  \hfill \break             
{\noindent \textbf {Answer 3.}} RAM is Random Acess Memory.  \vspace{2\baselineskip}

 {\noindent \textbf {Question 4.}} What is ROM  \hfill \break             
  {\noindent \textbf {Answer 4.}} ROM is Read Only Memory.  \vspace{2\baselineskip} \hfill \break

 {\noindent \textbf \LARGE This is 2nd  option of grouping question and snwer seperately } \bigskip

{\textbf \LARGE {Questions}} \par

{\noindent \textbf {\underline {A. MCQ}}}\hfill \break

{\noindent \textbf {Question 1.}} Which if the following is a secondary memory Devices.?\hfill \break  
    (a) keyboard    (b) Monitor (c) Hard Disk       (d) SMPS   \hfill \break    

{\noindent \textbf {Question 2.}} Recently deleted files are stored in\hfill \break           
    (a) Recycle bin (b) Taskbar (c) My computer (d) desktop     \hfill \break

{\noindent \textbf {\underline{B. Very Short Questions}}} \hfill \break
{\noindent \textbf {Question 3.}} What is RAM \hfill \break \par
{\noindent \textbf {\underline{C. Short Questions}}}\hfill \break
{\noindent \textbf {Question 4.}} What is ROM and its function?  \hfill \break \par
{\noindent \textbf \LARGE Answers}\par  \bigskip \par
{\noindent \textbf  {\underline{A. MCQ}}}\par
{\noindent \textbf {Answer 1.}} (c) Hard Disk.\hfill \break
{\noindent \textbf {Answer 2.}} ( a) Recycle bin.\hfill \break \par
{\noindent \textbf {\underline{ B. Very Short Questions}}}\par
{\noindent \textbf {Answer 3.}} RAM is Random Acess Memory.\hfill \break \par
{\noindent \textbf  {\underline{C. Short Questions}}}  \par
{\noindent \textbf {Answer 4.}} ROM is Read Only Memory.\hfill \break
\blindtext 

\end{document}
1
  • Can anyone guide me on use of package xsim. I find it very new and from the documentation, it seems to have so many customizable options. But the programming code seems to be tough for me as a beginner to design this as per my need.
    – Deb bijan
    Aug 2, 2018 at 14:35

1 Answer 1

2

Since you explicitly ask for a xsim solution in the comments:

Can anyone guide me on use of package xsim.

Here is a quick example showing the basic setup from your MWE:

\documentclass{article}
\usepackage{xsim}
\usepackage{tasks}

\DeclareExerciseProperty{mc}
\newcommand*\correct[1]{%
  \XSIMexpandcode{\SetExerciseProperty{mc}{(\alph{task}) \unexpanded{#1}}}%
  #1%
}
\newcommand*\mcanswer{\GetExerciseProperty{mc}}

\settasks{label=(\alph*),label-width=14pt}

\xsimsetup{
  % uncomment if you want the answer directly after the questions:
  % solution/print = true ,
  exercise/name = Question ,
  solution/name = Answer ,
  exercise/template = runin ,
  solution/template = runin ,
  print-solutions/headings-template = custom
}
\renewcommand*\theexercise{\arabic{exercise}.}
\loadxsimstyle{layouts}

\DeclareExerciseHeadingTemplate{custom}{\section*{Answers}}


\begin{document}

\begin{exercise}
  Which if the following is a secondary memory Devices?
  \begin{tasks}(4)
     \task keyboard \task Monitor \task \correct{Hard Disk} \task SMPS
  \end{tasks}
\end{exercise}
\begin{solution}
  \mcanswer.
\end{solution}

\begin{exercise}
  Recently deleted files are stored in
  \begin{tasks}(4)
    \task \correct{Recycle bin} \task Taskbar \task My computer \task desktop
  \end{tasks}
\end{exercise}
\begin{solution}
  \mcanswer.
\end{solution}

\begin{exercise}
  What is RAM?
\end{exercise}
\begin{solution}
  RAM is Random Acess Memory.
\end{solution}

\begin{exercise}
  What is ROM?
\end{exercise}
\begin{solution}
  ROM is Read Only Memory.
\end{solution}

% uncomment if you want to print a list of all solutions:
% \printsolutions

\end{document}

The one output:

enter image description here

And the other output:

enter image description here

You must log in to answer this question.

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