20

I would like to create a document which has a sequence of periods like:

......................
Date

and

............................
Signature

Is there any way to do it without typing all the periods myself (maybe even a way which was made for this often seen typographical quirk)?

3 Answers3

16

Use \dotfill:

\documentclass{article}
\usepackage{xparse}
\usepackage{multicol}

\NewDocumentCommand \dotbox {o O{.5\linewidth} m O{3ex} O{\linewidth}}
{
  \begin{minipage}{#2}
    \IfValueTF{#1}{#1}{\null}
    \\[#4]
    \makebox[#5]{\dotfill}
    \\
    #3
  \end{minipage}
}

\begin{document}
\hrule
\begin{multicols}{2}
  \dotbox[Please sign below:]{A. U. Thor}

  \dotbox[And your initials:]{A. U. T.}[6ex][6em]
\end{multicols}
\hrule
\vspace*{3cm}
\hrule
\dotbox[Sign here (4ex)][4cm]{\TeX.SX}[4ex]
\hspace*{2cm}
\dotbox[And here (3ex)][3cm]{\TeX.SX}
\hrule
\end{document}

output

Note that while this implementation allows you to have successive calls to \dotbox without a paragraph break, the baseline may be screwed up if you do so with differing dimensions, as can be seen from the second two uses.

David Carlisle
  • 757,742
Sean Allred
  • 27,421
12

Here is a sample TeX file to do it:

\documentclass{article}

\begin{document}

\makeatletter
\def\mydots#1{\hbox to #1{\leaders\hbox{$\m@th
        \mkern 1mu\hbox{.}\mkern 1mu$}\hfil}}
\makeatother    

\mydots{5pc}

\end{document}

\mydot{5pc} will put dots for a width 5pc. You can customize this.

Note: There is also a package named dashrule which has so may features.

Jagath
  • 4,287
  • 3
    FYI, you missed the \makeatother – Sean Allred Jul 26 '13 at 04:05
  • @SeanAllred: I don't think \makeatother is a must. You can check by giving @@@ later in the text. – Jagath Jul 26 '13 at 04:08
  • 4
    Put \@ifundefined{fakemacro}{Should I be able to do this?}{I think not.} right after \mydots. Writing @@@ is just like writing aaa or bbb as far as catcodes are concerned once you say \makeatletter; @ is used for internal macros and should not be generally available at the document level. – Sean Allred Jul 26 '13 at 04:17
  • your example is great - and dashrule is indeed even better. Thanks! – TheChymera Jul 26 '13 at 04:45
7

Using \hbox is not really recommended, because it can have unexpected effects.

\newcommand{\dottedline}[3][3ex]{%
  \par % end the current paragraph (if necessary)
  \nopagebreak % don't break a page here
  \vspace{#1}% space before the signature
  \noindent\makebox[#2]{\dotfill}% make the dotted line
  \\* % go to a new line without any page break
  \noindent#3% signature
  \par % end the paragraph
}

Here's a complete example:

\documentclass{article}

\newcommand{\dottedline}[3][3ex]{%
  \par % end the current paragraph (if necessary)
  \nopagebreak % don't break a page here
  \vspace{#1}% space before the signature
  \noindent\makebox[#2]{\dotfill}% make the dotted line
  \\* % go to a new line without any page break
  \noindent#3% signature
  \par % end the paragraph
  \vspace{#1}% space below the signature
}

\begin{document}

Please sign here:

\dottedline{6cm}{A. U. Thor}

And your initials:

\dottedline[1ex]{3cm}{A. U. T.}

\end{document}

enter image description here

egreg
  • 1,121,712