2

I'm trying to come up with my own command to fill what's left of the horizontal space with dots but I want the dots slightly lowered relative to the text. Here's my code :

\newcommand\ansfill{\raisebox{-.2\baselineskip}{\makebox[\linewidth]{\dotfill}}}

This works fine when there's nothing on my line

\ansline

but goes into \hbox overfull error when I add anything as the box from \makebox is always \linewidth.

e.g.

Example Text \ansfill

gives me an overfull hbox error.

I need a parameter that changes depending on what's left of the horizontal space. Something like :

\newcommand\ansfill{\raisebox{-.2\baselineskip}{\makebox[\whatever-that-is-left]{\dotfill}}}

Thanks.

2 Answers2

5

You can emulate the definition of \dotfill. I also add an optional argument to set a minimum width for the dots. The last example shows what would happen without the [8em].

\documentclass{article}

\newcommand{\ansfill}[1][0pt]{%
  \leavevmode
  \leaders
  \hbox to 0.44em{\hss\raisebox{-2pt}{.}\hss}%
  \hskip #1 plus 1fill
  \kern0pt
}

\begin{document}

Here's a question. \ansfill

Here's another longer question for which we need at least eight ems
of space for the answer. \ansfill[8em]

Here's another longer question for which we need at least eight ems
of space for the answer, even though the line would be almost filled up
with text. \ansfill[8em]

Here's another longer question for which we need at least eight ems
of space for the answer, even though the line would be almost filled up
with text. \ansfill % <--- Uh, oh!

\end{document}

enter image description here

egreg
  • 1,121,712
3

The dimension \linegoal defined by the package of the same name is probably the right thing here:

\documentclass[12pt]{article}
\usepackage{linegoal}

\newcommand\ansfill{\raisebox{-.2\baselineskip}{\makebox[\linegoal]{\dotfill}}}

\begin{document}

This is something \ansfill

\end{document}
AlexG
  • 54,894