1

Consider the following code/picture:

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\begin{document}
\noindent
\begin{tabular}{@{}p{2.62cm}@{}p{9.5cm}@{}}
$\varliminf,\varlimsup$ & test test test test test test test test test test test  \dotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test  \dotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test  \dotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test test  \dotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test test test  \dotfill 123\\
$\liminf,\limsup$ & idem  \dotfill 123 \\
\end{tabular}
\end{document}

Result

I'm not satisfied with the item 3 and 4 of 6: too few space(filled with dots!) before the number in 3, and in 4 the dots are missing. I tried to adapt this post, but without success. I just do not understand how it works. \zdotfill should not introduce unfilled space (unfilled=without dots), it should just have a minimal length of 1cm (filled with dots) and everything else should be as by \dotfill.

Wrong code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\newcommand{\zdotfill}{\hskip 1cm plus 1fill\dotfill}
\begin{document}
\noindent
\begin{tabular}{@{}p{2.62cm}@{}p{9.5cm}@{}}
$\varliminf,\varlimsup$ & test test test test test test test test test test test  \zdotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test  \zdotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test  \zdotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test test  \zdotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test test test  \zdotfill 123\\
$\liminf,\limsup$ & idem  \zdotfill 123 \\
\end{tabular}
\end{document}

1 Answer 1

2

You need to:

  • restrict the redefinition of \hfill to a group that finishes immediately after \dotfill, otherwise you are going to spoil other \hfill commands used in the document (possibly internally by LaTeX);

  • make sure the leaders inserted by \dotfill from your \zdotfill do not constitute a valid breakpoint, otherwise they just get discarded when they happen to be at the end of a line, according to TeX's paragraph breaking algorithm (what you witnessed);

  • make sure there is no space token before your calls to \zdotfill, otherwise this is yet another possible breakpoint at the precise place where you don't want one.

I'll rename your \zdotfill to \mindotfill in order not to confuse it with a command from zref (precisely, from its dotfill module).

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\newcommand{\mindotfill}{%
  \nolinebreak
  {\def\hfill{\hskip 1cm plus 1fill\relax}%
   \dotfill
  }%
}

\begin{document}
\noindent
\begin{tabular}{@{}p{2.62cm}@{}p{9.5cm}@{}}
$\varliminf,\varlimsup$ & test test test test test test test test test test test\mindotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test\mindotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test\mindotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test test\mindotfill 123\\
$\varliminf,\varlimsup$ & test test test test test test test test test test test test test test test\mindotfill 123\\
$\liminf,\limsup$ & idem\mindotfill 123\\
\end{tabular}
\end{document}

Screenshot

For your information, \dotfill is defined as:

\dotfill:
macro:->\leavevmode \cleaders \hb@xt@ .44em{\hss .\hss }\hfill \kern \z@ 

What \mindotfill does here is to modify the 〈skip〉 used by \cleaders, which is produced by \hfill in this definition (\hb@xt@ .44em{\hss .\hss } just produces an \hbox of suitable width containing a single dot). Leaders are assimilated to glue by TeX, that's why they get discarded at the end of a line.

8
  • wow! it is perfect! thank you May 18, 2019 at 7:36
  • Glad to here that. I added a little explanation of how this works at the end (but if you've never read about leaders, that won't be quite enough to understand everything—they are explained in the TeXbook).
    – frougon
    May 18, 2019 at 7:42
  • very interesting explanations, especially the local redefinition of a command. very usefull May 18, 2019 at 7:42
  • If you look closely, David Carlisle's post that you linked did the local redefinition correctly. :)
    – frougon
    May 18, 2019 at 7:43
  • 1
    Ah, okay. By the way, I'm not sure it's the best idea to name this command \zdotfill, because the dotfill module of the zref package already has a \zdotfill, which works differently.
    – frougon
    May 18, 2019 at 7:49

You must log in to answer this question.

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