3

I am using latex exam class and need to sectioning questions like

\documentclass[12pt,paper=a4,answers]{exam}
  \begin{document}
    \begin{questions}
    \section{First Section}
    \question
    First question
    \question
    Second question
    \section{Second Section}
    \question
    First question
    \question
    Second question
  \end{questions}
\end{document}

This works, but doesn't align properly under section heading as well as not numbering like 1.1, 1.2 etc. Any option for that?

Probably a solution is updating question font and size to that of a section heading and use part/sub part. Any help to do this?

  • 1
    Welcome to TeX.SE!. Please provide complete small document (MWE: Minimal Working Example) with \documentclass{...} on the beginning, used package and defined new commands, followed with \begin{document} showed code snipped and \end{document}on the end. Without MWE we can only guessing what is going on. – Zarko Aug 29 '16 at 0:50
  • Updated with MWE. – Ras Aug 29 '16 at 0:59
2

Here is one solution, although I'm not sure how this will affect the built in answers and grading. Normally exam organizes by \question, \part and \subpart.

\documentclass[12pt,paper=a4,answers]{exam}
\usepackage{etoolbox}
\usepackage{blindtext}% MWE only

\renewcommand{\thequestion}{\thesection.\arabic{question}}
\patchcmd{\questions}{10.}{\thequestion.}{}{}% fix left margin

\begin{document}
  \section{First Section}
  \begin{questions}
    \question
    \blindtext
    \question
    Second question
    \end{questions}
  \section{Second Section}
  \begin{questions}
    \question
    First question
    \question
    Second question
  \end{questions}
\end{document}

demo


The patch will make each question margin precisely aligned, but different questions will have different margins.


This solution uses the \fullwidth macro inside the questions environment. I assume you aren't planning on using a table of contents.

\documentclass[12pt,paper=a4,answers]{exam}
\usepackage{etoolbox}% opener for can of worms
\usepackage{blindtext}% MWE only

\newcommand{\mysection}[1]% #1 = title
{\stepcounter{section}%
\setcounter{question}{0}%
\fullwidth{\smallskip\textbf{\large #1}}}

\renewcommand{\thequestion}{\thesection.\arabic{question}}
\patchcmd{\questions}{10.}{\thequestion.}{}{}% fix left margin

\begin{document}
  \begin{questions}
   \mysection{First Section}
    \question
    \blindtext
    \question
    \blindtext
   \mysection{Second Section}
    \question
    First question
    \question
    Second question
  \end{questions}
\end{document}

second demo

  • This is fine, but still indent is not proper for the second line of questions, see – Ras Aug 30 '16 at 3:04
  • link Image – Ras Aug 30 '16 at 3:54
  • My idea was make basic question font larger (size of section heading) without marks/points thus it can be used for heading, then use part/sub part for making actual questions. Is it possible? then there will not be problem for indent, but I am not sure about section numbers in this case. – Ras Aug 31 '16 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.