LaTex 考试:LaTex 新手 - 缩进问题,修复文本超过多行时不雅且不一致的问题

LaTex 考试:LaTex 新手 - 缩进问题,修复文本超过多行时不雅且不一致的问题

我一直在尝试使用考试类来替代 word,并试图使格式尽可能类似于各国使用的 12 年级格式。以下是此类格式的一个例子:

没有部分的问题:

在此处输入图片描述

部分问题:

在此处输入图片描述

多项选择:

在此处输入图片描述

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

\usepackage{newtxtext,newtxmath} %Font%
\usepackage{xcolor} %Color package%
\usepackage[onehalfspacing]{setspace}
\usepackage{graphicx}
\graphicspath{{./images/}} %Directory for images: Samefolder/images%
\usepackage{geometry}
\usepackage{tikz}
\usepackage{setspace}
\singlespacing

%Choose page margins%
\geometry{
    a4paper,
    total={168.494mm,275mm},
    left=13mm,
    top=10mm,
}

\setlength\linefillheight{1cm} %Space between answer lines%
\pointsinrightmargin %Marks aligned to the right margin, left juxtaposed%
\pointsdroppedatright
\pointformat{\thepoints} %Format of marks%
\marksnotpoints %Display marks instead of points%
\setlength{\rightpointsmargin}{0.5cm} %Indent marks%

\renewcommand{\thepartno}{\textbf{\alph{partno}}} %Formatting parts%
\renewcommand{\partlabel}{\thepartno.} 
\renewcommand{\partshook}{\setlength\leftmargin{0pt} \setlength\itemsep{1cm}}
\renewcommand{\questionshook}{\setlength{\itemsep}{1.5cm}} %Formatting questions%

\qformat{ \textbf{Question \thequestion} (\totalpoints\ marks) \hfill} %Question title format%

\pagestyle{headandfoot}  %header%
\extraheadheight[0.7cm]{0.7cm}
\firstpageheader{\scriptsize{YEAR CLASS EXAMINATION XX}}{\scriptsize{\thepage}}{}
\runningheader{\scriptsize{YEAR CLASS EXAMINATION XX}}{\scriptsize{\thepage}}{}\firstpagefooter{}{}{}
\runningfooter{}{}{}
\renewcommand{\questionshook}{\setlength{\itemsep}{1.2cm}} %Formatting questions%
\renewcommand\choicelabel{\bfseries{\Alph{choice}.}} 
\renewcommand{\choiceshook}{%
    \setlength{\leftmargin}{1mm}% 
    \setlength{\labelwidth}{\labelsep}%
    \setlength{\itemsep}{0.25mm}
}

\begin{document}

\begin{questions} 

%%%%%%%%%%%% Page 1 %%%%%%%%%%%%
\question %Question 1%
    \begin{parts}
        \part[2] Let $y=3x^2(\log_e(x^3))$. Find the derivative of $y$.
        \droppoints
        \fillwithlines{7cm}
        \part[2] Let $f(x)=\sin^2(x)$. Find $f'\left(\pi\right)$. 
        \droppoints
        \fillwithlines{7cm}
    \end{parts}
\pagebreak

%%%%%%%%%%%% Page 2 %%%%%%%%%%%%
\question %Question 2%
\parbox[4mm][]{\linewidth}{}\par %Correct Spcing if the intial question text goes over multiple lines%
\hspace*{-5.8mm}{\parbox{475pt}
    {This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines \\
    This is then on the next line.      
    }}\vspace*{4mm} %Correct alignment%
        \begin{parts}
            \part[1] State the asymptotes. 
            \droppoints
            \fillwithlines{4cm}
            \part[3] Sketch the function on the set of axes below. Label all intercepts, and all asymptotes with their equation.
            \droppoints
            \begin{center}
                \includegraphics[scale=1.3]{q2_b_axes}
            \end{center}
        \end{parts} 
    
    \question[1]  
    \hspace*{-5.8mm}{\parbox{475pt}{Text}}
    \begin{choices}
        \choice One
        \correctchoice Two
        \choice Three
        \choice Four
        \choice Five
    \end{choices}
    
    \question[1]  
    \par %Correct Spcing if the intial question text goes over multiple lines%
    \hspace*{-5.8mm}{\parbox[t]{475pt}{This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines}}\vspace*{2mm} %Correct alignment%
    \begin{choices}
        \choice One
        \correctchoice Two
        \choice Three 
        \choice Four
        \choice Five
    \end{choices}
    
        
\end{questions}
    
\end{document}

其结果为: 在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

乍一看还不错,但使用 qformat 时,初始问题文本会缩进。我使用了某种框和负间距来适应它,但它并没有完全对齐。另一个问题是,在 qformat 之后,当问题文本超过一行时,“问题 X”和问题第一行之间的文本会缩小。

由于我计划大规模制作文档,我想知道是否有更优雅的解决方案来复制 12 年级考试风格。如果在考试课上无法做到这一点,是否可以简单地不使用考试命令并创建可以复制我想要的格式的新命令。

先谢谢了。

答案1

尝试对此代码进行一些更改\qformat和添加钩子以使所有内容左对齐。

e4

\setlength{\iseparation}{<space>}可以使用(示例中使用 1ex)调整水平标签间距 。

在问题文本中,您可以使用\newline开始新行或\par开始新段落。

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

\usepackage{newtxtext,newtxmath} %Font%
\usepackage{xcolor} %Color package%
\usepackage[onehalfspacing]{setspace}
\usepackage{graphicx}
\graphicspath{{./images/}} %Directory for images: Samefolder/images%
\usepackage{geometry}
\usepackage{tikz}
\usepackage{setspace}
\singlespacing

%Choose page margins%
\geometry{
    a4paper,
    total={168.494mm,275mm},
    left=13mm,
    top=10mm,
}

\setlength\linefillheight{1cm} %Space between answer lines%
\pointsinrightmargin %Marks aligned to the right margin, left juxtaposed%
\pointsdroppedatright
\pointformat{\thepoints} %Format of marks%
\marksnotpoints %Display marks instead of points%
\setlength{\rightpointsmargin}{0.5cm} %Indent marks%
    
\pagestyle{headandfoot}  %header%
\extraheadheight[0.7cm]{0.7cm}
\firstpageheader{\scriptsize{YEAR CLASS EXAMINATION XX}}{\scriptsize{\thepage}}{}
\runningheader{\scriptsize{YEAR CLASS EXAMINATION XX}}{\scriptsize{\thepage}}{}\firstpagefooter{}{}{}
\runningfooter{}{}{}
    
%%****************************************************** <<<<<<<<<<<<<<<<<<<<<
\qformat{%%Question title format  changed <<<<<<<<<<<
    \parbox{\linewidth}{\textbf{Question~\thequestiontitle}\ (\totalpoints\ marks) \\[-1.5ex]}% changed <<<<<<<<<
}

\renewcommand{\questionshook}{%%Formatting questions changed <<<<<<<<<
    \setlength{\leftmargin}{0pt}%
    \setlength{\labelwidth}{-\labelsep}%
}
\newlength{\iseparation}
\setlength{\iseparation}{1ex}% use to change the label separation

\renewcommand\choicelabel{\bfseries{\Alph{choice}.}} 
    \renewcommand{\choiceshook}{% added <<<<<<<<<<<<
    \setlength{\leftmargin}{0pt}
    \setlength{\labelwidth}{-\labelsep}%
    \def\makelabel##1{##1\hskip1\iseparation}%   
}

\renewcommand{\thepartno}{\textbf{\alph{partno}}} %Formatting parts%
\renewcommand{\partlabel}{\thepartno.} 

\renewcommand{\partshook}{% added <<<<<<<<<<<<
    \settowidth{\leftmargin}{W.\hskip\labelsep}%
    \setlength{\labelwidth}{-\labelsep}%
    \def\makelabel##1{\hskip-\leftmargin##1\hskip\iseparation}%   
}
%%******************************************************

\begin{document}
    \begin{questions} 
        
        %%%%%%%%%%%% Page 1 %%%%%%%%%%%%
        \question %Question 1%
        \begin{parts}
            \part[2] Let $y=3x^2(\log_e(x^3))$. Find the derivative of $y$.
            \droppoints
            \fillwithlines{7cm}
            \part[2] Let $f(x)=\sin^2(x)$. Find $f'\left(\pi\right)$. 
            \droppoints
            \fillwithlines{7cm}
        \end{parts}
    
    \question[3]%Question 2
     Compute $\displaystyle\int_0^1 x^2 \, dx$.
        \fillwithlines{\fill}
        \pagebreak
        
        %%%%%%%%%%%% Page 2 %%%%%%%%%%%%
        \question %Question 3% Use \par instead of \\ to start a new paragraph <<<<<<<<<<<<<<<<<<<
        This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines. \newline This is then on the next line.      \par This starts a new paragraph.
        \begin{parts}
            \part[1] State the asymptotes. 
            \droppoints
            \fillwithlines{4cm}
            \part[3] Sketch the function on the set of axes below. Label all intercepts, and all asymptotes with their equation.
            \droppoints
            \begin{center}
                \includegraphics[scale=0.5]{example-image}
            \end{center}
        \end{parts} 
        
        \question[1]   %Question 4%
        Text
        \begin{choices}
            \choice One
            \correctchoice Two
            \choice Three
            \choice Four
            \choice Five
        \end{choices}
        
        \question[1]  %Question 5%
        This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines This Text Goes Over Multiple Lines %Correct alignment%
        \begin{choices}
            \choice One
            \correctchoice Two
            \choice Three 
            \choice Four
            \choice Five
        \end{choices}       
        
    \end{questions}
    
\end{document}

相关内容