6

I'm a newbie to LaTeX as of a couple days ago, and was delighted to hear of an exam package that would ease my pain. However, I've worked out that the exam paper I am trying to emulate definitely did not use the exam package based on things like how the marks are done and where question sub-parts go.

So I want to emulate the question lines in it - I tried looking in the exam.cls source code but it is very esoteric to me as a beginner. I've been trying to use \line(1, 0){some number} but that can easily go past the right margin - which I don't want it to do - i.e. I want a line which I can start at an indented or tabbed position and it will stop at the right margin.

See below for an image of how this looks.

Exam Question

1 Answer 1

4

You can copy the code for \fillwithlines straight out of exam.cls, and it will work inside of an enumerate environment:

\documentclass[12pt]{article}

%--------------------------------------------------------------------
\makeatletter
%                            \fillwithlines


% \fillwithlines takes one argument, which is either a length or \fill
% or \stretch{number}, and it fills that much vertical space with
% horizontal lines that run the length of the current line.  That is,
% they extend from the current left margin (which depends on whether
% we're in a question, part, subpart, or subsubpart) to the right
% margin.
%
% The distance between the lines is \linefillheight, whose default value
% is set with the command
%
% \setlength\linefillheight{.25in}
%
% This value can be changed by giving a new \setlength command.
%
% The thickness of the lines is \linefillthickness, whose default value
% is set with the command
%
% \setlength\linefillthickness{.1pt}
%
% This value can be changed by giving a new \setlength command.


\newlength\linefillheight
\newlength\linefillthickness
\setlength\linefillheight{.25in}
\setlength\linefillthickness{0.1pt}

\newcommand\linefill{\leavevmode
    \leaders\hrule height \linefillthickness \hfill\kern\z@}


\def\fillwithlines#1{%
  \begingroup
  \ifhmode
    \par
  \fi
  \hrule height \z@
  \nobreak
  \setbox0=\hbox to \hsize{\hskip \@totalleftmargin
          \vrule height \linefillheight depth \z@ width \z@
          \linefill}%
  % We use \cleaders (rather than \leaders) so that a given
  % vertical space will always produce the same number of lines
  % no matter where on the page it happens to start:
  \cleaders \copy0 \vskip #1 \hbox{}%
  \endgroup
}
\makeatother
%--------------------------------------------------------------------

\newcommand{\e}{\mathrm{e}}

\begin{document}
\begin{enumerate}
\item Let $y = (3x^{2} - 5x)^{5}$.  Find $\frac{dy}{dx}$.
  \fillwithlines{2in}

\item Let $f(x) = x \e^{3x}$.  Evaluate $f'(0)$.
\fillwithlines{2in}
\end{enumerate}

\end{document}
5
  • Ok cool - so I will put that in a custom .cls file in the same directory, something like "examlines.cls" - I've taken a brief look at how to 'import' that but haven't seen how to do it. Is it something like \usepackage{examlines}?
    – nebffa
    Jun 4, 2013 at 8:32
  • 1
    @nebffs: Yes, \usepackage{examlines} is exactly right, but you also need to remove the lines \makeatletter and \makeatother if you've put that code into a style file. Jun 5, 2013 at 1:22
  • Sorry about being away for so long - I hope I haven't left it too long. Thanks for your answer - however I specifically don't want to enumerate the questions as that gives me a formatting I don't like - is there a way to do this not in an enumerate environment?
    – nebffa
    Jun 9, 2013 at 10:37
  • Hey Phil - I've been able to work it out. Instead of using \fillwithlines I can instead use multiple \linefill commands coupled with a custom \tab command each line to create multiple lines (e.g. \tab \linefill times 4 to create 4 lines). Your answer was close and gave me lots of help so I'm going to accept it - thanks!!!!
    – nebffa
    Jun 10, 2013 at 2:08
  • @nebffa: Glad to hear it helped. Jun 10, 2013 at 5:30

You must log in to answer this question.

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