Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Do you always want an \hrulefill to represent the missing word(s)? What about breaks over lines? –  Werner Mar 13 at 3:24
    
Welcome to TeX.SX! A tip: You can use backticks ` to mark your inline code as I did in my edit. –  Adam Liter Mar 13 at 3:35
    
Werner: I do not always want an \hrulefill. What are breaks over lines? –  HYC Mar 13 at 5:55
1  
Welcome to TeX.SX :-) Consider the exam document class. –  Sean Allred Mar 13 at 6:37
add comment

4 Answers 4

up vote 1 down vote accepted

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

share|improve this answer
    
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 at 12:25
    
I updated the answer to allow for left aligned answers. –  Alex Grede Mar 13 at 12:32
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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

share|improve this answer
    
An extra space for the \answer command and an extra space for any word in the \answerwords would be great. Since handwriting is more spaced. –  Manuel Mar 13 at 10:56
    
@Manuel Done, per your request. –  Steven B. Segletes Mar 13 at 11:01
1  
It's not OP's request. Just me making a suggestion :P –  Manuel Mar 13 at 11:10
    
censor is nice, but one downside is that the positioning of the text when censored in this case is not the same as when uncensored. The blanks move, if you will. Not always an issue, but sometimes makes it more difficult to match things up quickly when you are looking at a whole page of these. –  cslstr Mar 13 at 11:25
    
@cslstr See revised answer. –  Steven B. Segletes Mar 13 at 12:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.