正确缩进两种不同格式的考试题目

正确缩进两种不同格式的考试题目

我正在尝试将问题的缩进与两种不同的格式对齐(一种用于扩展响应,另一种用于多项选择)。无论我怎么努力,我都只能使用各种随机数来尝试正确对齐,而且我无法弄清楚如何对齐多项选择的问题 - 调整 questionhook 通常会触及第二个问题,并且似乎\renewcommand{\questionshook}在文档中间不起作用(与\renewcommand{\choiceshook}etc 不同),这意味着我似乎无法独立处理每个部分。

这就是我现在所拥有的:

我所拥有的图像

这就是我的愿望:

我所渴望的形象

这是我的代码,不幸的是,由于与其他问题的交互,它并不是很短:

\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}

答案1

定义了一个新命令\questionx来处理第二种问题风格。这样就\qformat不需要超出它的范围了。

标签和文本之间的额外间隔(蓝线和红线之间)由控制\xtrasep(本例中设置为 0.7cm)。解决方案中不涉及任何神奇数字。

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}

答案2

可以运行\questionshook多次,但您必须\end{questions}先运行。

红线距离文本区域边缘恰好1cm。

请注意,这使用左对齐的数字,而不是右对齐的数字,向左移动直到看起来不错。

演示

\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

我们使用\uplevel命令

\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}

在此处输入图片描述

相关内容