[Tex/LaTex] How to have a horizontal line work inside a tabbing environment

horizontal alignment

Preface: I am very new to Latex, and may have missed some things here.

I have a custom macro to create a horizontal line – not by my making, simply copied and pasted from the exam package.

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

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

Unfortunately I have discovered that it doesn't work inside a tabbing environment:

\begin{document}
\linefill
\begin{tabbing}
\linefill

The first \linefill generates a line, but the second does not. How can I change my Latex to have this work with the tabbing environment?

Here is an example .tex file that compiles and doesn't produce any horizontal lines, even though I want it to: (also note that \usepackage{examlines} refers to a custom .sty file I made that houses the code from the exam package for \linefill)

\documentclass[a4paper, 12pt]{article}
\usepackage{mathptmx}
\usepackage{examlines}
\newcommand{\tab}{\hspace*{1em}}

\begin{document}
\begin{tabbing}

\textbf{Question 1} \\ 
\textbf{a.} \tab \= Let $y = \left(- 3 x^{2} - 3 x\right)^{3}$. Find $\frac{dy}{dx}$. \\ 
\\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\textbf{b.} \tab Let $f(x) = e^{2 x^{2} + 9 x + 5}$. Evaluate $f'(-1)$. \\ 
\\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 


Let $f(x) = \left(- 3 x^{2} - 3 x\right)^{3} = u^{3}, u = - 3 x^{2} - 3 x$ \\ 
$f'(x) = 3 u^{2} \times u'$ \\ 
$f'(x) = - 81 x^{2} \left(x + 1\right)^{2} \left(2 x + 1\right)$ \\ 
\\
$f'(x) = \left(4 x + 9\right) e^{2 x^{2} + 9 x + 5}$ \\ 
$f'(-1) = \frac{5}{e^{2}}$ \\ 

\end{tabbing}
\end{document}

Here is the code in examlines.sty: (I don't use all of it)

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

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

Best Answer

I've used LaTeX for over 25 years and I don't think I've ever really seen a good use for tabbing but anyway I think that you want lines to look like this?

enter image description here

\documentclass[a4paper, 12pt]{article}
\usepackage{mathptmx}

\newcommand{\tab}{\hspace*{1em}}
\makeatletter
\def\linefill{%
\leavevmode
\leaders\hrule\hskip\dimexpr\textwidth -\@tempdima\mbox{}}
\begin{document}
\begin{tabbing}

\textbf{Question 1} \\ 
\textbf{a.} \tab \= Let $y = \left(- 3 x^{2} - 3 x\right)^{3}$. Find $\frac{dy}{dx}$. \\ 
\\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\textbf{b.} \tab Let $f(x) = e^{2 x^{2} + 9 x + 5}$. Evaluate $f'(-1)$. \\ 
\\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 
\> \linefill \\ 


Let $f(x) = \left(- 3 x^{2} - 3 x\right)^{3} = u^{3}, u = - 3 x^{2} - 3 x$ \\ 
$f'(x) = 3 u^{2} \times u'$ \\ 
$f'(x) = - 81 x^{2} \left(x + 1\right)^{2} \left(2 x + 1\right)$ \\ 
\\
$f'(x) = \left(4 x + 9\right) e^{2 x^{2} + 9 x + 5}$ \\ 
$f'(-1) = \frac{5}{e^{2}}$ \\ 

\end{tabbing}

\noindent X\dotfill X
\end{document}
Related Question