0

I'm trying to align the indentation of questions with two different formats (one for extended responses, the other, multiple choice). As much as I try, I am stuck using various random numbers to try to align it properly, and I can't figure out how to get the question for the multiple choice aligned - adjusting questionshook will often touch the second question, and seemingly \renewcommand{\questionshook} doesn't seem to work in the middle of the document (unlike \renewcommand{\choiceshook} etc), which means I can't seem to treat each part standalone.

This is what I have right now:

image of what I have

This is what I desire:

image of what I desire

This is my code, which is unfortunately not super short because of the interactions with other questions:

\documentclass[%
    12pt, 
    a4paper,
]{exam}

\usepackage[showframe=true]{geometry}

\usepackage{calc}
\renewcommand{\questionshook}{%
    \setlength{\leftmargin}{0pt}%
    \labelwidth\leftmargin\advance\labelwidth-\labelsep%
}

% Dimensions tuned to be about right.
\renewcommand{\partshook}{
    \setlength{\topsep}{-0.02in}%
    \setlength{\leftmargin}{\leftmargin+0.08in}%
    \setlength{\labelsep}{0.22in}%
}

\newlength{\mcindent}
\setlength{\mcindent}{0.55cm}

\renewcommand{\choiceshook}{%
% The dimensions are tuned to be about right. I should figure out how to not have random numbers.
    \settowidth{\leftmargin}{W\hspace{\labelsep}\hspace{0.18in}\hspace{\mcindent}}
}

\begin{document}

\begin{questions}
% multiple choice format
\noqformat
\renewcommand{\thequestion}{\textbf{\arabic{question}}}
% This makebox sort of works for the first line.
\renewcommand{\questionlabel}{\makebox[1cm][l]{\thequestion}}
\pointsinmargin\pointformat{}

% an adjustbox from https://tex.stackexchange.com/a/35934/200609 does not work properly as all there is some indentation from the number already
\question[1]%
I wish to have both lines of this sentence aligned with the A/B/C/D multiple choice options.

\begin{choices}
\choice Oh really?
\choice Here I will demonstrate how to type a long sentence, to confirm that it works here.
\end{choices}

% extended response format
\qformat{\textbf{Question \thequestion} (\totalpoints\ marks)\hfill}
\pointsinrightmargin
\pointformat{\textbf{\themarginpoints}}

\question%
This question should remain in the same format, aligned to the border. I do no know how to do this whilst doing the choice answer indented using questionshook, since redefining it does not seem to work.
\begin{parts}
\part[1] Ideally the text in these parts should be at the same indent as the multiple choice options, but it is closer enough at the moment that I can ignore it.

\part[2] This is another long sentence to make sure indentation works properly, as I tend to forgot to fix that.
\end{parts}

\end{questions}

\end{document}
0

3 Answers 3

3

A newcommand \questionx was defined to deal with the second question style. In that way \qformat is not needed ouside its scope.

The additional separation between the labels and the text (between the blue and red lines) is control by \xtrasep (set to 0.7cm for this example). No magic numbers are involved in the solution.

f

\documentclass[%
12pt, 
a4paper,
]{exam}

\usepackage[showframe=true]{geometry}   
\usepackage{calc}

\usepackage{enumitem}% added    

\renewcommand{\questionlabel}{\unskip\bfseries\thequestion}

\newlength{\xtrasep}
\setlength{\xtrasep}{0.7cm} % set blank space beteween label and text
    
\renewcommand{\choiceshook}{% 
\settowidth{\labelwidth}{A.}%   
\setlength{\labelsep}{1em} % after A., B.
\setlength{\leftmargin}{\labelindent+\labelwidth+\labelsep-\itemindent}
}   

\renewcommand{\questionshook}{% 
    \settowidth{\labelwidth}{(m)}%  
    \setlength{\labelsep}{\xtrasep}
    \setlength{\leftmargin}{\labelindent+\labelwidth+\labelsep-\itemindent}
}

\newcommand{\questionx}[1]{% added <<<<<<<<<<<<<<<<<<<<
\qformat{\textbf{Question \thequestion} (\totalpoints\ marks)\hfill}
\pointsinrightmargin
\pointformat{\textbf{\themarginpoints}} 
\question
\hspace*{-\leftmargin}\parbox{\textwidth}{#1}
}
    
\renewcommand{\partshook}{% 
    \settowidth{\labelwidth}{(m)}%  
    \setlength{\labelsep}{\xtrasep}
    \setlength{\leftmargin}{0pt}
    \def\makelabel##1{##1}% 
}

\begin{document}
    
    \begin{questions}
        % multiple choice format
%       \noqformat
        \pointsinmargin\pointformat{}       

        \question[1]%
        I  wish to have both lines of this sentence aligned with the A/B/C/D multiple choice options.
        
        \begin{choices}
            \choice Oh really?
            \choice Here I will demonstrate how to type a long sentence, to confirm that it works here.
        \end{choices}   
    
    \questionx{%
    This question should remain in the same format, aligned to the border. I do no know how to do this whilst doing the choice answer indented using questionshook, since redefining it does not seem to work.}
    \begin{parts}
        \part[1] Ideally the text in these parts should be at the same indent as the multiple choice options, but it is closer enough at the moment that I can ignore it.
        
        \part[2] This is another long sentence to make sure indentation works properly, as I tend to forgot to fix that.
    \end{parts}
        
    \end{questions}
\end{document}
4
  • Hmm, this seems to have the behaviour of indenting text which was between questions; this seems obvious in hindsight as being treated as part of the question text, however, when googling a solution to that I found \fullwidth, which seems to work the same way that {\hspace*{-\leftmargin}\parbox{\textwidth}{#1}} does. Is there much of a difference? Commented Sep 19, 2021 at 1:17
  • You can try \question\mbox{}\fullwdthl{#1} or \question \mbox{}\uplevel{#1} but both will insert a blank line, Commented Sep 19, 2021 at 8:56
  • Okay, thanks :) Commented Sep 19, 2021 at 9:29
  • You probably don't want a page break in the middle of a question anyway. Commented Sep 20, 2021 at 3:46
3

It is possible to run \questionshook more than once, but you have to \end{questions} first.

The red line is precisely 1cm from the edge of the text area.

Note, this uses left justified numbers, not right justified numbers shifted left until they look good.

demo

\documentclass[%
    12pt, 
    a4paper,
]{exam}

\usepackage[showframe=true]{geometry}
\usepackage{xcolor}
\usepackage{calc}

\renewcommand{\questionshook}{\setlength{\labelwidth}{1cm-\labelsep}%
  \setlength{\leftmargin}{\labelwidth+\labelsep}}

\renewcommand{\choiceshook}{\setlength{\labelwidth}{1em}%
  \setlength{\leftmargin}{\labelwidth+\labelsep}%
  \setlength{\itemindent}{0pt}}

\renewcommand{\partshook}{\setlength{\labelwidth}{1cm-\labelsep}%
  \setlength{\leftmargin}{\labelwidth+\labelsep}%
  \setlength{\itemindent}{0pt}}

\renewcommand{\questionlabel}{\makebox[\labelwidth][l]{\thequestion}}
\renewcommand{\partlabel}{\makebox[\labelwidth][l]{(\thepartno)}}
\renewcommand{\choicelabel}{\makebox[\labelwidth][l]{\thechoice}}
\begin{document}

\begin{questions}
% multiple choice format
\noqformat
\renewcommand{\thequestion}{\textbf{\arabic{question}}}
% This makebox sort of works for the first line.

\pointsinmargin\pointformat{}

% an adjustbox from https://tex.stackexchange.com/a/35934/200609 does not work properly as all there is some indentation from the number already
\question[1]%
I wish to have both lines of this sentence aligned with the A/B/C/D multiple choice options.

\begin{choices}
\choice Oh really?
\choice Here I will demonstrate how to type a long sentence, to confirm that it works here.
\end{choices}

\xdef\lastquestion{\arabic{question}}
\end{questions}

\renewcommand{\questionshook}{\setlength{\labelwidth}{1cm-\labelsep}% not actually needed
  \setlength{\leftmargin}{0pt}%
  \setlength{\itemindent}{\labelwidth+\labelsep}}

\begin{questions}
\setcounter{question}{\lastquestion}


% extended response format
\qformat{\textbf{Question \thequestion} (\totalpoints\ marks)\hfill}
\pointsinrightmargin
\pointformat{\textbf{\themarginpoints}}

\question
This question should remain in the same format, aligned to the border. I do no know how to do this whilst doing the choice answer indented using questionshook, since redefining it does not seem to work.

\begin{parts}
\part[1] 
Ideally the text in these parts should be at the same indent as the multiple choice options, but it is closer enough at the moment that I can ignore it.

\part[2] This is another long sentence to make sure indentation works properly, as I tend to forgot to fix that.
\end{parts}

\fullwidth{\hspace{1cm}\smash{\textcolor{red}{\rule{0.5pt}{9cm}}}}% show alignment

\end{questions}

\end{document}
3
  • Thanks for the answer. I have gone with another solution, as this does not align the indented parts correctly. Commented Sep 19, 2021 at 1:17
  • OTOH, it does greatly simplify the code. Not sure what "correctly" implies. Commented Sep 19, 2021 at 14:34
  • The long-form questions parts are not indented. Commented Sep 20, 2021 at 3:08
2

We the use of the \uplevel command

\documentclass[%
    12pt, 
    a4paper,
]{exam}

\usepackage[showframe=true]{geometry}

\usepackage{calc}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand{\questionshook}{%

\setlength{\labelsep}{8.2mm}
     \setlength{\leftmargin}{\labelsep+\labelwidth}
    
 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Dimensions tuned to be about right.
\renewcommand{\partshook}{
     \setlength{\topsep}{-0.02in}%
    \setlength{\leftmargin}{0pt}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \renewcommand{\choiceshook}{%
 \setlength{\leftmargin}{8.2mm}
}

% remove unwanted spaces before labels
\renewcommand{\questionlabel}{\unskip\thequestion.}
\renewcommand{\choicelabel}{\unskip\thechoice.}

\begin{document}


\begin{questions}

\pointsinmargin\pointformat{}


\question[1]% 

I wish to have both lines of this sentence aligned with the A/B/C/D multiple choice options.

\begin{choices}
\choice Oh really?
\choice Here I will demonstrate how to type a long sentence, to confirm that it works here.
\end{choices}

% extended response format
\qformat{\textbf{Question \thequestion} (\totalpoints\ marks)\hfill}
\pointsinrightmargin
\pointformat{\textbf{\themarginpoints}}

\question \mbox{}
\uplevel{%
This question should remain in the same format, aligned to the border. I do no know how to do this whilst doing the choice answer indented using questionshook, since redefining it does not seem to work.}

\begin{parts}
\part[1] Ideally the text in these parts should be at the same indent as the multiple choice options, but it is closer enough at the moment that I can ignore it.

\part[2] This is another long sentence to make sure indentation works properly, as I tend to forgot to fix that.
\end{parts}

\end{questions}

\end{document}

enter image description here

1
  • What's the difference here between \uplevel and the solution by @Simon Dispa which is \hspace*{-\leftmargin}\parbox{\textwidth}{#1}? Commented Sep 19, 2021 at 1:18

You must log in to answer this question.

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