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}
PeptideChain
  • 1,335

1 Answers1

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.

frougon
  • 24,283
  • 1
  • 32
  • 55
  • wow! it is perfect! thank you – PeptideChain May 18 '19 at 07: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 '19 at 07:42
  • very interesting explanations, especially the local redefinition of a command. very usefull – PeptideChain May 18 '19 at 07:42
  • If you look closely, David Carlisle's post that you linked did the local redefinition correctly. :) – frougon May 18 '19 at 07:43
  • that is the point: I could not understand what he was doing, without an explanation... :) – PeptideChain May 18 '19 at 07:45
  • 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 '19 at 07:49
  • I've made slight changes to the \zdotfill / \mindotfill definition: 1) The \nolinebreak doesn't need to be in the group where \hfill is redefined; 2) \relax is better than the space token to prevent taking stuff such as minus 1cm from what follows in \dotfill's definition (this doesn't happen with the current def, but is better in principle). – frougon May 18 '19 at 08:02
  • Actually, adding the \relax here is debatable. Adding it makes the expansion of the new \hfill contain more than just a 〈skip〉, even if it doesn't change the output; not adding it makes us rely on how it is used, i.e., on the fact that in \dotfill's definition, the \hfill is not followed by a plus or a minus keyword. This is probably a reasonably safe assumption, and I assume that is the reason why David Carlisle didn't add the \relax. – frougon May 18 '19 at 08:14