6

I want to make a blank between texts on both ends of a line. For example,a blank between texts on both ends of a line

\begin{enumerate}
\item There \hrulefill\ in the room.
\end{enumerate}

But, the above appears in student's version only, and I want to make a teacher's version where the answer is also printed in the blank. I don't have any idea but

\begin{enumerate}
\item There \underline{\makebox[100pt][l]{is a chair}} in the room.
\end{enumerate}

The method is not satisfactory because the length of the blank is unknown in advance.

My problems:

  1. How to put text on an \hrulefill?

  2. (A bonus question) I found out that the vertical position of the horizontal rule generated by \hrulefill and \underline is different. How can I control the vertical position of these horizontal rules?

Adam Liter
  • 12,567
HYC
  • 329

4 Answers4

5

Here's a simple implementation:

\documentclass{article}

\newif\ifteacher % starts out false

\newcommand{\fillanswer}[2][\fill]{%
  \unskip\ \lhrulefill{#1}%
  \ifteacher\makebox[0pt]{#2}\fi
  \lhrulefill{#1}\ \ignorespaces}
\newcommand{\lhrulefill}[1]{%
  \leavevmode
  \leaders\hrule height -.3ex depth \dimexpr .3ex+.4pt\relax % define the leader
  \hskip\glueexpr#1/2\relax\relax % how much it should extend
  \kern0pt
}


\begin{document}

\begin{enumerate}
\item There \fillanswer{is a chair} in the room.

\item There \fillanswer[5cm]{is a chair} in the room.

\teachertrue
\item There \fillanswer{is a chair} in the room.

\item There \fillanswer[5cm]{is a chair} in the room.
\end{enumerate}

\end{document}

enter image description here

The default value for the optional argument is \fill, which means that essentially \hrulefill is executed (but the rule is lowered). Actually we set two rules and the zero width box in between them when \ifteacher is set to true.

egreg
  • 1,121,712
  • I have the very same task as in third item of your list so adopted your solution. Suddenly the problem arise: I have small space right in the middle of the hrule, so it seems that it is actually two rules separated by a space. Would you please explain hot to get rid of this space (proof pic: http://postimg.org/image/xy0xfpftr/ the space is under letter в). – Artem Pelenitsyn Jul 28 '14 at 18:29
  • 1
    @ArtemPelenitsyn You're missing a % after \makebox[0pt]{#1} – egreg Jul 28 '14 at 19:08
4

This method uses some redefinitions of the \uline macro from ulem to print out just the underlining from some text (with the text itself invisible). (See this answer for a similar solution.)

I added a bit of space on each side of the text so the blank is a bit larger than it would need to be (to allow for handwriting). As illustrated, this will also gracefully handle very long "blanks" that end up extending over multiple lines.

The Student Version is made by keeping the first \let\filltheblanks... command and commenting the second. The Teacher version comments the first command and keeps the second.

\documentclass[]{report}

\usepackage{enumerate}
\usepackage[normalem]{ulem}

\begin{document}
\LARGE % Size seemed appropriate for this type of assignment

% Fill-in-the-blank command
\newcommand{\fillintheblank}[1]{\uline{\qquad#1\qquad}}

% For Student Version
\let\filltheblanks\phantom

% For Teacher Version
\let\filltheblanks\null

% Redefined \uline
\makeatletter
\def\UL@putbox{\ifx\UL@start\@empty \else % not inner
  \vrule\@width\z@ \LA@penalty\@M
  {\UL@skip\wd\UL@box \UL@leaders \kern-\UL@skip}%
    \filltheblanks{\box\UL@box}%
  \fi}
\makeatother
%%%%%%%%%%%%%%%%


\begin{enumerate}[1.]

\item There \fillintheblank{was a dog} in the room.

\item There \fillintheblank{was a very, large, wet and disgusting looking dog} outside my door.

\end{enumerate}

\end{document}

Student Version:

student version

Teacher Version:

teacher version

cslstr
  • 6,545
4

A Variation on the answer at Create fill-in-the-blank version of a document with ability to toggle blanks on and off

It provides \answer for continuous underline (with line breaks) and \answerwords for word-by-word underline. Uncomment \TeacherCopy in the preamble, and get the teacher version.

EDIT, per Manuel's request, I leave extra space for the student's answer, which I accomplish by setting the fontsize to \Huge prior to commencing the underlining blackout, and then resetting it afterward (note that this does not affect the vertical height allocated for the answer, since the Huge text is converted into a vertically-challenged rule of the same width).

REEDITED so that teacher version provides same word spacing as student version.

The \censorruleheight and \censorruledepth can be altered to change the elevation the rule thickness and placement, respectively.

\documentclass{article}
\usepackage{censor}
\usepackage{xcolor}
\usepackage{readarray}
\usepackage{ifthen}
\censorruledepth=-.2ex
\censorruleheight=.1ex
\newcounter{index}
\def\mysize{\Huge}
\def\answer#1{\mysize\xblackout{#1}\normalsize}
\def\answerwords#1{\mysize\blackout{#1}\normalsize}
\def\TeacherCopy{%
  \def\answer##1{%
    \color{red}%
    \getargsC{##1}%
    \setcounter{index}{0}%
    \whiledo{\theindex<\narg}{%
      \stepcounter{index}%
      \setbox0=\hbox{\mysize\csname arg\romannumeral\theindex\endcsname}%
      \underline{$\vphantom{g}$%
                 \makebox[\wd0]{\csname arg\romannumeral\theindex\endcsname}}%
      \mysize\ \normalsize%
    }%
    \unskip%
    \color{black}%
  }%
  \let\answerwords\answer%
}
%\TeacherCopy
\parindent0pt
\begin{document}
\begin{enumerate}
\item And the answer to life, the universe, and everything, is \answer{forty two}.

\item The beginning six words of the Gettysburg Address are 
\answerwords{Four score and seven years ago}.

\end{enumerate}
\end{document}

Student copy:

enter image description here

Teacher copy:

enter image description here

2

While cslstr's method is more robust, one way to do this is to replace the \hrulefill with one that uses underlines using \xleaders.

\documentclass[letter,10pt]{article}
\newcommand{\ulfrule}{\xleaders\hbox{\underline{ }}\hfill\kern0pt}
\begin{document}
\begin{enumerate}
\item There \hrulefill{} in the room.
\item There \ulfrule{} in the room.
\item There \ulfrule{}\underline{is a chair}\ulfrule{} in the room.
\end{enumerate}
\end{document}

Which produces: example output

If you wanted the answer left aligned you can remove the beginning \ulfrule{} before the answer:

\documentclass[letter,10pt]{article}
\newcommand{\ulfrule}{\xleaders\hbox{\underline{ }}\hfill\kern0pt}
\begin{document}
\begin{enumerate}
\item There \hrulefill{} in the room.
\item There \ulfrule{} in the room.
\item There \underline{is a chair}\ulfrule{} in the room.
\end{enumerate}
\end{document}

More on what \xleaders does can be found in this answer

Alex Grede
  • 1,093
  • This is almost what I need. However, I hope that the answer be aligned left rather than center inside the blank, yet a little space say 0.5ex should be left at the beginning of the blank. Could you teach me how to obtain it? – HYC Mar 13 '14 at 12:25
  • I updated the answer to allow for left aligned answers. – Alex Grede Mar 13 '14 at 12:32