2

I would like to create an exam class document with questions taking the form "Question 1" or "Problem 1" and points listed in the left margin.

Changing the qformat eliminates the points altogether unless I include them in the new qformat. E.g. the following

\qformat {Problem~\thequestiontitle. \hfill} \pointsinmargin 

produces no point values at all. I can add \thepoints somewhere in the qformat and they will appear, but not in the margin.

The following MWE stamps the points (which should be in the margin) right on top of the question label.

\documentclass [addpoints, letterpaper, 12pt] {exam} \renewcommand {\questionlabel} {\textbf{Problem}~\thequestiontitle.} \bracketedpoints \pointsinmargin \begin {document} \begin {questions} \question [20] Some text. \end {questions} \end {document} 

points on top of question label

The exam class seems well designed and well documented, so I'm guessing that I'm missing a nice solution to this problem. But I have only been able to produce moderately better results by adding in \hspace* etc.

Edit: I would like "Problem 1" to be flush with the rest of the text, not pushed out into the margin as is achieved by this answer.

Edit 2: By increasing leftmargin as suggested by cfr and then by increasing itemindent I can achieve the first result below. But I would really like the second version below, where the label and text are flush with the page margin and the points are listed in the page margin.

two Questions with labels and text flush

2
  • 1
    Does this answer solve your issue? Commented May 2, 2024 at 19:50
  • Not entirely; the method there pushes the question label out into the margin; I'd prefer for it to be flush with the rest of the text. I will add a clarification. Commented May 2, 2024 at 20:48

2 Answers 2

2
+100

The points are in the margin, it turns out. The problem is that questions doesn't expect a label as wide as yours, so the label protrudes into the left margin i.e. it is the label which needs fixing (or, rather, the space allowed for it) rather than the location of the points per se.

I used geometry with pass,showframe to confirm this in testing. I've left this commented in the code below.

I defined a new command to make things easier, though it doesn't do much.

  • \mkquestionlabel[<label>](<punctuation>){<content>} takes 2 optional and 1 mandatory argument. By default, it reproduces your format with a bold Problem, a non-breakable space, the number or title and a full-stop.

We can then use this to adjust the width allowed for labels in the questions environment by defining a \widestquestionlabel. I used 99 as the dummy content here. Obviously, adjust this as necessary.

\newcommand {\widestquestionlabel} {\mkquestionlabel{99}} 

We can then use the \questionshook facility to adjust the space left for the label.

\renewcommand \questionshook {% mod from pkg code \settowidth{\leftmargin}{\widestquestionlabel \hskip\labelsep}% } 

This produces hanging items i.e. the label is wider than the standard indentation of the list. If you want the content indented by the entire width of the label, you could use

\renewcommand \questionshook {% mod from pkg code \settowidth{\leftmargin}{\widestquestionlabel \hskip\labelsep}% \labelwidth\leftmargin\advance\labelwidth-\labelsep } 

But this will lead to a lot of white space on the left if you have long labels.

Complete code:

\documentclass [addpoints, letterpaper, 12pt] {exam} % \usepackage[pass,showframe]{geometry} \NewDocumentCommand \mkquestionlabel { O {Problem~} D () {.} m } {% #1 prefix #2 suffix #3 number/title \textbf{#1}#3#2% } \renewcommand {\questionlabel} {\mkquestionlabel{\thequestiontitle}} \newcommand {\widestquestionlabel} {\mkquestionlabel{99}} \bracketedpoints \pointsinmargin \renewcommand \questionshook {% mod from pkg code % % We use the default definition of \makelabel % % so as not to interfere with \qformat commands. % % \def\makelabel##1{\hss\llap{##1}}% % \settowidth{\leftmargin}{10.\hskip\labelsep}% % \labelwidth\leftmargin\advance\labelwidth-\labelsep % \partopsep=0pt % \questionshook \settowidth{\leftmargin}{\widestquestionlabel \hskip\labelsep}% } \begin {document} \begin {questions} \question [20] Some text. \end {questions} \end {document} 

EDIT

The space for marginal notes is on the right but, if you nonetheless wish to push the points into the left margin, you can do it. However, you need to use \pointsformat and add the square brackets yourself.

The following seems to work.

\documentclass [addpoints, letterpaper, 12pt] {exam} % ateb: https://tex.stackexchange.com/a/717305/ \usepackage[pass,showframe]{geometry} \usepackage{calc} \usepackage{kantlipsum}% don't use in your real document \newlength \qnlabelwidth \qnlabelwidth=0pt \NewDocumentCommand \mkquestionlabel { O {Problem~} D () {.} m } {% #1 prefix #2 suffix #3 number/title \textbf{#1}#3#2% } \NewDocumentCommand \mkquestionlabelbox { m } {% \makebox[\qnlabelwidth] {% \mkquestionlabel{#1}\hfill }% } \renewcommand {\questionlabel} {% \mkquestionlabelbox{\thequestiontitle}% } \AddToHook{begindocument/end} {% \settowidth \qnlabelwidth {% \mkquestionlabel{99}% }% } \bracketedpoints \pointsinmargin \pointformat{\llap{[\themarginpoints] \hspace*{\qnlabelwidth}}} \renewcommand \questionshook {% mod from pkg code % % We use the default definition of \makelabel % % so as not to interfere with \qformat commands. % % \def\makelabel##1{\hss\llap{##1}}% % \settowidth{\leftmargin}{10.\hskip\labelsep}% % \labelwidth\leftmargin\advance\labelwidth-\labelsep % \partopsep=0pt % \questionshook \itemindent=\qnlabelwidth \advance \itemindent by \labelsep \leftmargin=0pt \labelwidth=\qnlabelwidth } \begin {document} \begin {questions} \question [20] \thepoints \kant[1] \end {questions} \end {document} 

Apologies for the lack of a picture. Okular-on-X has a bug which means my PDFs are fine, but images cropped from them or produced by conversion are worthless.

EDIT

Attempt at picture:

output with page frame shown by geometry

8
  • This doesn't give me exactly what I want, but it is helpful. (Thanks!) As you say, this solution produces hanging labels, when I would like the text to be flush with the label. I can fix this by increasing itemindent by an appropriate amount. But that leaves me with a lot of whitespace on the left that I would prefer to be rid of. Can't I get the points in the actual page margin? I will add another clarification. Commented May 7, 2024 at 1:07
  • @ZachN exam is configured so the space for margin notes is on the right. Do you want to change that so it is on the left? Or? Commented May 7, 2024 at 1:45
  • @ZachN See edit. Commented May 7, 2024 at 7:32
  • 1
    @ZachN (3) I think you're right about calc. I needed it for some earlier iteration which didn't work, I think. (1) I also thought there must be a simpler solution, but I finally concluded the package just doesn't use margin in the ordinary sense. It means the margin of the list and not the page. But it does support taking total control of typesetting the points, so it does not require hacking. I'm just using interfaces the package supports: the hook for the environment and \pointsformat etc. (2) There's an option for it, but it made the points vanish when I tried it. cont. Commented May 7, 2024 at 20:00
  • 1
    I didn't try very hard, though, because you asked for them on the left. What I really meant was: LaTeX provides an area for marginal notes. That's the column you see on the right with showframe. There's a standard setup for putting notes there. I was asking you to clarify if you wanted them in the left margin, which doesn't have space for marginal notes by default here. But then you posted the edit and it was clear what you wanted ;). Marginal notes aren't perfect: they can get detached from the location where they're set, so that mechanism mightn't be ideal. You could alter the page layout. Commented May 7, 2024 at 20:05
0

I tied using this from the exam class document.

\documentclass [addpoints, letterpaper, 12pt] {exam} \renewcommand {\questionlabel} {\textbf{Problem }~\thequestiontitle.} \bracketedpoints \nopointsinmargin %REPLACED YOUR CODE. \begin {document} \begin{questions} \question[20] Some text. \end{questions} \end {document} 
1
  • This doesn't answer the question since it doesn't put the points in the margin. Commented May 6, 2024 at 1:27

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.