How to have a horizontal line work inside a tabbing environment
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?
\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}
I like David's answer, but I couldn't let go the opportunity to use \tikzmark
.
In this, \tikzmark
is used to place a mark at the desired x-position where the lines should begin, and then \DrawLines
is used to draw the lines; the syntax is
\DrawLines[<length>]{<number>}{<mark>}
where <number>
is a positive integer representing the amount of lines to be drawn, and <mark>
is a previously stablished mark set with \tikzmark
; <length>
allows control over the vertical separation between consecutive lines.
The code:
\documentclass[a4paper, 12pt]{article}
\usepackage{mathptmx}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\newcommand{\tab}{\hspace*{1em}}
\newcounter{tmp}
\makeatletter
\def\whileexpr#1\do#2{%
#1\expandafter\@iden\else\expandafter\@gobble\fi
{#2\whileexpr#1\do{#2}}%
}
\makeatother
\newcommand\tikzmark[1]{%
\tikz[remember picture,overlay]\node[inner xsep=0pt] (#1) {};}
\newcommand\DrawLines[3][\baselineskip]{%
\\
\setcounter{tmp}{0}%
\begin{tikzpicture}[remember picture,overlay]
\foreach \i in {1,...,#2}
{\path[draw] let \p1=(#3), \p2=(current page text area.west) in ([yshift=-\i*#1]\x1,0|-0,\y1-\baselineskip) -- ( $ ([yshift=-\i*#1]current page text area.east|-#3) + (0,-\baselineskip) $ );}
\end{tikzpicture}%
\whileexpr\ifnum\thetmp<#2\relax\do{%
\>\mbox{}\\[\dimexpr#1-\baselineskip\relax]\stepcounter{tmp}\relax
}%
\>\mbox{}\\[3pt]
}
\begin{document}
\begin{tabbing}
\textbf{Question 1} \\
\\
\textbf{a.} \tab \=\tikzmark{A}Let $y = \left(- 3 x^{2} - 3 x\right)^{3}$. Find $\frac{dy}{dx}$.
\DrawLines{4}{A}%
\\
\textbf{b.} \tab\tikzmark{B}Let $f(x) = e^{2 x^{2} + 9 x + 5}$. Evaluate $f'(-1)$. \\
\\
\DrawLines[25pt]{7}{B}%
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}
THe code needs two or three runs to stabilize.
I used the \whileexpr
macro from Ahmed's Musa's answer
to looping in tabular.