1

I want to add sections and titles for questions in exam class. I used report class but I am wondering if I can get something similar with exam class . I want something like this (se also the picture),

\documentclass[12pt, a4pape]{exam} % 'twoside' when printing
\pdfcompresslevel=9
\usepackage[margin=2.5cm, twoside]{geometry}
\linespread{1.3}
%\setcounter{secnumdepth}{3}
\usepackage[utf8]{inputenc}             % UTF-8 input
\usepackage[english]{babel}             % Set language to english
\usepackage{blindtext}                  % Use \Blinddocument or \blindmathpaper
\usepackage{graphicx,graphics}
%\usepackage{subfig}
\usepackage{color,xcolor,colortbl}  
\usepackage{cite}
\graphicspath{ {/Users/farha/Documents} }
\usepackage{fancyhdr}
\usepackage{url}                    
\usepackage{hyperref}
\def\UrlBreaks{\do\/\do-}

\usepackage{amsmath,amsfonts,amsthm,mathtools,physics,bm}
\usepackage{booktabs,multirow,multicol,tabularx,floatrow,float,makecell,hhline,arydshln}                            
\usepackage{gensymb}                                                                    
\usepackage{parskip}                                
\usepackage[sharp]{easylist}        
\usepackage{makeidx,listings,tikz-cd,enumitem}              
%\usepackage[linesnumbered,ruled]{algorithm2e}                                      
\usepackage[expansion=false]{microtype} 
\usepackage[toc,page]{appendix}                                                                     
\usepackage[T1]{fontenc}
\usepackage[makeroom]{cancel}
\usepackage{xpatch,lipsum,framed,etoolbox}
\usepackage{geometry,array,subcaption}  
\usepackage{placeins,afterpage} 
\usepackage{textcomp,siunitx} % to get celsisus degree
\usepackage{pdfpages} % add pdf pages
\usepackage{subfiles}
\usepackage{listings}
\usepackage{ragged2e}
\usepackage[toc,page]{appendix}
%\usepackage[dvipsnames*,svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{mdframed}
\begin{document}
    \maketitle
    %\tableofcontents
    \thispagestyle{empty}
    
\begin{tcolorbox}[width=\textwidth ]
    \section*{PART 1\\
         Without help tools}
\end{tcolorbox}

\begin{questions}
 \question Assignment 1 (5 points) 

Let f  be a function given by  $f(x)=x^{3}+\pi x+4$
\begin{parts}
\part 
\part
\part 
\end{parts}
 \question Assignment 2 (5 points)

\begin{parts}
    \part 
    \part
    \part 
\end{parts}
\end{questions}
\begin{tcolorbox}[width=\textwidtt]
\section*{PART 2 \\
    With help tools}    
\end{tcolorbox}
\begin{questions}
    \question Assignment 1 (5 points) 
    
    Let f  be a function given by  $f(x)=x^{3}+\pi x+4$
    \begin{parts}
        \part 
        \part
        \part 
    \end{parts}
    \question Assignment 2 (5 points)
    
    \begin{parts}
        \part 
        \part
        \part 
    \end{parts}
\end{questions}

\end{document}

enter image description here

1
  • 1
    See section 6.2 of the exam class manual. Graphical \part titles are tricky, by not uncommon. Apr 10, 2022 at 21:08

2 Answers 2

1

First, the right usage is not

\question Assignment 1 (5 points) 

Let f  be a function given by  $f(x)=x^{3}+\pi x+4$

…you have to give the points as option, and let the class do the formating (and you'll be able to change the presentation in an homogenous way easely later)

\question[5] Assignment 1 

Let f  be a function given by  $f(x)=x^{3}+\pi x+4$

…also questions are automatically numbered, and you don't have to manage the numbering by yourself when you rearange later

\question[5]  

Let f  be a function given by  $f(x)=x^{3}+\pi x+4$

From here, I understand that you want the numbering to be prefixed with “Assignment” and to be bolded. Here comes qformat{Format Specification} to customise question number lines. Class documentation says that:

Format specification must contain some stretchability (e.g., at least one \hfill or \dotfill or \hrulefill or ...) and can contain the commands

  • \thequestion, which expands to the question number,
  • \thequestiontitle, which expands to
    • the title of the question, if this question was defined using a \titledquestion command instead of a \question command, or
    • the number of the question, if this question was defined using a \question command,
  • \thepoints, which expands to
    • the number of points followed by the argument to the last \pointname command, if there were points specified for the question, or
    • nothing, if no points were specified for the question
  • \totalpoints, which expands to the total number of points specified for the question and all of its parts, subparts, and subsubparts. The command \totalpoints expands to \pointsofquestion{\arabic{question}}.

OK, so something like the following will do the trick (checked/compiled with pdflatex)

\documentclass[12pt,a4paper]{exam} % 'twoside' when printing
%\usepackage[margin=2.5cm,twoside]{geometry}
%\linespread{1.3}
%\usepackage[utf8]{inputenc}             % UTF-8 input
%\usepackage[english]{babel}             % Set language to english
%\usepackage[T1]{fontenc}
\usepackage{tcolorbox}

\title{Adding titles in exam class}
\author{F.O}
\date{Apr 10, 2022 at 16:15}

\renewcommand*{\thesection}{PART~\arabic{section}}

\begin{document}
  \maketitle
  %\tableofcontents
  \thispagestyle{empty}
  \qformat{\textbf{Assignment~\thequestion}\quad(\thepoints)\hfill}
    
  \begin{tcolorbox}[width=\textwidth ]
    \section{Without help tools}
  \end{tcolorbox}

  \begin{questions}
    \question[5] 

      Let $f$ be a function given by  $f(x)=x^{3}+\pi x+4$
      \begin{parts}
        \part foo
        \part bar
        \part baz
      \end{parts}
    \question[5]

      \begin{parts}
        \part fiz
        \part boo
        \part buz
      \end{parts}
  \end{questions}

  \begin{tcolorbox}[width=\textwidth ]
    \section{With help tools}    
  \end{tcolorbox}
  \begin{questions}
    \question[5]

      Let $f$ be a function given by  $f(x)=x^{3}+\pi x+4$
      \begin{parts}
        \part alpha
        \part beta
        \part charlie
      \end{parts}
    \question[5]

      \begin{parts}
        \part delta
        \part echo
        \part fiona
      \end{parts}
  \end{questions}

\end{document}

Note that you should use titlesec to refine formatting by centring part+number and going to new line before text. You should also consider creating a command for the titles in box. Hope that helps.

2
  • Nice, but your code can‘t compile when copied. Can you please make it complete? Thank you
    – MS-SPO
    Feb 3 at 10:03
  • 1
    Well, there was some errors in your post (I mean it won't compile either) and I've added another one by putting \newline in the counter redefinition. Corrected and full preamble added now.
    – gildux
    Feb 6 at 11:25
0

According to the exam class manual the commands \part, \section etc are available (the class is built on the article class so \chapter is not included).

What, if anything, did you try?

3
  • I just added a picture for the format I want .
    – F.O
    Apr 10, 2022 at 18:11
  • @F.O OK, you have shown what you want. What did you try with the exam class, not the report class? Apr 11, 2022 at 17:33
  • I just modified the question and added what I tried.
    – F.O
    Apr 13, 2022 at 16:54

You must log in to answer this question.

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