11

The \vrule primitive has a nice charcateristic: it has the ability of adapting itself to the height and depth of the enclosing box:

\documentclass{article}

\newcommand\TestBox{\parbox[c][3cm][c]{1em}{\centering A}}

\begin{document}‎‎

\noindent
\TestBox\vrule\TestBox

\noindent
\rule{10pt}{1cm}\,\vrule\,\rule[3cm]{10pt}{1cm}

\end{document}

enter image description here

Is it possible to define a similar command, say \vdotfill, which is a dotted equivalent of \vrule? If so, how? Otherwise, why not?

4
  • You have to measure the height and depth; only \vrule has the ability of adapting itself to the height and depth of the enclosing box.
    – egreg
    Jul 29, 2015 at 19:40
  • @egreg so there's no hope in trying to define \vdotfill to automatically adapt to the surrounding height and depth? Jul 29, 2015 at 19:42
  • @GonzaloMedina With \valign. ;-)
    – egreg
    Jul 29, 2015 at 19:47

2 Answers 2

9

\dotfill is defined via \cleaders and an infinite glue specification (\hfill). A similar definition of \vdotfill has two problems:

  • \leaders and friends only work with horizontal glues in horizontal mode or vertical glue in vertical mode. Orthogonal variants are not available.

  • There are two vertical directions (height and depth) instead of one horizontal. That raises lots of new questions: Where does the fill start? How are direction(s) and and amount(s) specified?

PDF operators

If the TeX rule is implemented by a line in the PDF page description, then the graphics state could be changed to get a dashed line, may be with rounded line ends. However, a rule can also be implemented by a filled rectangle, where this trick does not work.

Clumsy workaround for pdfTeX

The vertical positions via \pdfsavepos (the module zref-savepos of project zref provides an interface) can be added in pdfTeX at the base line and via \vadjust (after) and \vadjust pre (before the current line). The latter is a specialty of pdfTeX. The the depth and height can be calculated and the vertical dotted line can be set.

However, this will not work in all circumstances. For example, other material might be added via \vadjust interfering with the position measurement.

Solution sketch with LuaTeX

LuaTeX provides a new feature "attribute". Thus, a normal \vrule with the correct width can be set with an attribute meaning a vertical dotted line. Then the built page (its node tree) is traversed to find such rules to replace them with dotted vertical lines.

0
4

Only \vrule can adapt its height plus depth to the dimension of the outer box. If you need to put dotted vrule between two or more boxes with unknown height and depth then you can use \valign:

\def\putbox{\afterassignment\putboxA\setbox0=}
\def\putboxA{\aftergroup\putboxB}
\def\putboxB{\global\dimen0=\dp0 \dp0=0pt \box0 & \kern\dimen0 \cr}
\def\puttext#1{\putbox\hbox{#1}}
\def\vdotfil{\omit\span\omit
   \kern-.1pt\xleaders\vbox{\kern.1pt\hbox{.}\kern.1pt}\vfil\kern-.1pt\cr}

\valign{\vfil#&#\vfil\cr
  \putbox\vbox{\kern 5cm \hbox{A}} % more than 5 cm height, 0pt depth
  \vdotfil
  \putbox\vbox{\hbox{B\vrule depth2cm width0pt}} % B height, 2 cm depth
}

\valign{\vfil#&#\vfil\cr
  \puttext {Hello}\vdotfil \puttext {you}
}

\end                                                              

The \vdotfil will have more than 5 cm height and 2 cm depth in this example. The second example is equivalent to \hbox{Hello\vrule you}.

The \valign is designed with two "lines" here, first "line" includes only heights of boxes and second "line" only depths of the same boxes. The macro \putbox does the separation of the following box to its "height part" and "depth part" and it puts the results to the appropriate "lines". The reason of this complication is that we need to set the boxes from left to right with aspect of their baseline as in normal horizontal mode.

You must log in to answer this question.

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