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.

Similar to the \dotfill command, but with your own text, rather than dots.

If the string was: kitty!

The entire line would look like the following: kitty!kitty!kitty!kitty!kitty!kitty!kitty!kitty!kitty!

Is there any way to do this?

share|improve this question
2  
Have a look at the file latex.ltx. THere you will find the definition of dotfill and hruefil –  Marco Daniel Dec 15 '11 at 20:40

1 Answer 1

up vote 27 down vote accepted

One way of doing this is using leaders:

enter image description here

\documentclass{article}

\newcommand\kitty{\leavevmode\xleaders\hbox{kitty!}\hfill\kern0pt}

\begin{document}
This is a test. \kitty \par
This is a test.

\noindent \kitty
\end{document}

The general format for constructing leaders is \leaders<box or rule><glue> (which repeats <box or rule>). There are three kinds of leaders that you can use: \leaders, \cleaders and \xleaders. Here is an informal description of each, taken from The Advanced TeXBook:

When \leaders is used, TeX first locates the innermost box A containing the \leader command. It then fills up A, from the left, with copies of the leader. There may be some space left on the right. ...

The \cleaders command centers the leaders in the leader window, regardless of the size of the enclosing box A. There is normally some space left on both sides of the window. The \xleaders is still different. It distributes the window space evenly between the individual copies of the leader.

Here, and just for fun, the difference between using \kitty with \leaders, \cleaders and \xleaders:

enter image description here

\documentclass{article}
\usepackage{showframe}% http://showframe
\begin{document}
\noindent \leaders\hbox{kitty!}\hfill\kern0pt \par
\noindent \cleaders\hbox{kitty!}\hfill\kern0pt \par
\noindent \xleaders\hbox{kitty!}\hfill\kern0pt
\end{document}

Also see the TeXBook for reference (chapter 21 Making Boxes, p 223):

The dots you see before your eyes here . . . . . . . . . . . . are called "leaders" because they lead your eyes across the page; such things are often used in indexes or tables of contents. The general idea is to repeat a box as many times as necessary to fill up some given space. TeX treats leaders as a special case of glue; no, wait, it's the other way around: TeX treats glue as a special case of leaders. Ordinary glue fills space with nothing, while leaders fill space with any desired thing. In horizontal mode you can say

\leaders<box or rule>\hskip<glue>

and the effect will be the same as if you had said just \hskip<glue>, except that the space will be occupied by copies of the specified <box or rule>. The glue stretches or shrinks in the usual way.

share|improve this answer
    
Exactly what I was looking for, thanks! –  Walmart_Hobo Dec 15 '11 at 21:35

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.