1

I want to build a \dotfill command where I can specify a minimum length. I have tried:

\makebox[0.88em]{\dotfill}\dotfill

As the standard spacing of dotfill is 0.44em, so I get exactly two dots. However, there is a slightly bigger spacing between the first two dots and the dots from the second \dotfill command.

Does anyone have an idea how I can solve that?

1
  • 1
    Welcome to TeX.SE!
    – JamesT
    Commented Apr 15, 2023 at 9:57

2 Answers 2

4

you can copy the definition of \dotfill replacing \hfill by skip with a larger natural size:

enter image description here

\documentclass{article}

%\def\dotfill{%
%  \leavevmode
%  \cleaders \hb@xt@ .44em{\hss.\hss}\hfill
%  \kern\z@}
%  \MakeRobust\dotfill

\DeclareRobustCommand\mydotfill{%
  \leavevmode
  \cleaders \hbox to.44em{\hss.\hss}\hskip .88em plus 1fill
  \kern0pt }


\begin{document}

1 a\dotfill b

2 a\dotfill b\hspace{0pt  plus 1filll}c

{\parfillskip=.5\textwidth minus .5\textwidth

3 a\dotfill b

}

4 a\mydotfill b

5 a\mydotfill b\hspace{0pt  plus 1filll}c

{\parfillskip=.5\textwidth minus .5\textwidth

6 a\mydotfill b

}
\end{document}
1
  • Thanks a lot, it's exactly the solution I was looking for!
    – ljjs
    Commented Apr 15, 2023 at 14:58
0

That is a XY problem. David answer solved exactly what you asked (fix a minimun of dots, then +1) but not what you want (find a good solution for dot lines with 0-1 dots).

My crystal ball said that fix a minimum of dots is not that what you want, because force things in this way can produce a big Overfull \hbox (see black part of the MWE).

What my crystal ball cannot see is what other solution could you consider good for these cases, because it depends a lot of contents and personal preferences.

One simple solution could be enclose "a" and/or "b" in \parboxes, to ensure that that a+b will not take more than \linewidth-0.88em.

Another more complex (it need two runs!), is check if the width of a+b is smaller that this (taking at least b as argument of the macro) so you can use the standard \dotfill but otherwise do ... what you consider better. Just as example, the fix in the MWE is move the "b" part to the next line with a half dotted line.

The MWE also show that omitting the curly braces ({}) will take as first argument only the next character, so when "b part" is a word or sentence, it can produce wrong results.

mwe

\documentclass[a6paper,draft]{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{linegoal,xcolor,lipsum}
\parindent0pt\parskip0pt
\newlength\ihave
\newlength\remain
\newlength\ineed

\begin{document}
\DeclareRobustCommand\mydotfill{%
  \leavevmode
  \cleaders \hbox to.44em{\hss.\hss}\hskip .88em plus 1fill
  \kern0pt }

No argument (fake \verb-\dotfill-):

\rule{.75\linewidth}{1.5ex} \mydotfill b\par
\rule{.85\linewidth}{1.5ex} \mydotfill b\par
\rule{.95\linewidth}{1.5ex} \mydotfill b\par

\rule{.75\linewidth}{1.5ex} \mydotfill basic\par
\rule{.85\linewidth}{1.5ex} \mydotfill basic\par
\rule{.95\linewidth}{1.5ex} \mydotfill basic\par

\renewcommand\mydotfill[1]{%
\settowidth{\ihave}{#1}%
\setlength{\remain}{\dimexpr\linegoal}%
\setlength{\ineed}{\dimexpr\ihave+.88em}%
\ifdim\remain>\ineed \dotfill#1\else\\[-1ex]%
\mbox{}\hfill$\vdots$\dotfill#1\fi} 

\color{blue}

Argument  is next character   % better with curly braces ...

\rule{.75\linewidth}{1.5ex} \mydotfill b\par 
\rule{.85\linewidth}{1.5ex} \mydotfill b\par
\rule{.95\linewidth}{1.5ex} \mydotfill b\par 

\color{red}
But it should not :  % ...  because this

\rule{.75\linewidth}{1.5ex} \mydotfill basic\par 
\rule{.85\linewidth}{1.5ex} \mydotfill basic\par
\rule{.95\linewidth}{1.5ex} \mydotfill basic\par 

 \color{magenta}
Argument  is the next word/setence:

\rule{.75\linewidth}{1.5ex} \mydotfill{basic}\par 
\rule{.85\linewidth}{1.5ex} \mydotfill{basic}\par
\rule{.95\linewidth}{1.5ex} \mydotfill{basic approach method}\par 


\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .