6

I am trying to add dotted line from left-edge to right-edge of tabular after rows. There are 3-problems with my best attempt (code & screenshot below): 1) The length of the dotted line equals width of minipage instead of table, 2) The dots don't exactly start at left edge of the table (there is a slight gap), 3) Reducing dot size also changes the start point of the dotted line, further mismatching the start points of lines with different dot sizes (I would like to have lines with different dot sizes, but all starting & ending at same edge). The left edge of the leftmost dot should touch the left edge of table (just like \hrule used on the first line), and right edge of the rightmost dot should touch the right edge of the table. I am using lualatex.

NOTE: I have come across hacks on stack exchange that use dashes instead of dots, I am looking for dots so please don't post any dash answers. Also, I cannot move to another environment for now, so it has to be a solution for tabular environment. Also, please don't post tikz or other slow drawing tricks. If it isn't clear from the description: I don't intend to manually specify length of the table length like n pt/cm/in, the solution would be able to figure out length of table just like the \hrule I use for the first line. Lastly: Given the emphasis on PDF tagging & accessibility in TUG 2020, the solution ideally won't make pdf-accessibility text-to-speech utility to start speaking 'dot dot dot dot dot...' a gazillion times.

Code:

% >> lualatex table.tex
\documentclass[notitlepage,letterpaper]{article}
\usepackage{array}
\begin{document}

\begin{minipage}[t][1in][t]{3in}
    Hello world!\\
    \begin{tabular}[t]{@{}rll@{}}
            \noalign{\hrule height 0.5pt}
        a & some & text \\
            \noalign{\dotfill}
        b & some & other text \\
            \noalign{\dotfill}
        b & some more & text \\
            \noalign{\dotfill}
    \end{tabular}%
\end{minipage}

\end{document}

Screenshot: (I intend to start smaller sized dotted line from left edge of red box, and end it at its right edge (ideally the dots touching the edge)) Screenshot of output

2
  • for changing the size of dots -- tex.stackexchange.com/a/52849/197451
    – js bibra
    Commented Sep 16, 2020 at 7:00
  • The question says no tikz-based solution... Moreover, the reason I ask that the solution should work with different dot size is not that I cannot change size, it has more to do with the fact that different dot sizes start at different points (if you zoom in). One can change dot size with something like \noalign{{\fontsize{4pt}{\baselineskip}\selectfont\dotfill}}, but as you would see the first dot's starting point again varies by size. So one cannot just add a hack that deducts some constant side-bearing size, it has to be dependent on the dot size.
    – codepoet
    Commented Sep 16, 2020 at 8:22

3 Answers 3

6

Adapted from my answer at Dotted line instead of \hline in table environment, to include \xleaders rather than \leaders, for improved flushness, and to provide an optional inclusion of dots for each column's margin, allowing it to be used with @{} column-margin specifications. Also, it now works for more than a 2-column tabular.

In an effort to better match left and right margins, two additional EDITS were made to the adaptation:

  1. specified sidebearings to the dot were accounted for.

  2. A final right-column kern was required to subtract off one \replength of leader minus the width of the (sidebearing-free) dot

The values of \replength and \dotscale can be changed on a column by column basis, if desired. Unfortunately, I can not construct the dots as a single leader, but must handle it column by column. Since I use \xleader to achieve flushness, this means that the dot separation in each column will be slightly different, based on the column width and the values of \replength and \tabcolsep.

\documentclass{article}
\usepackage{graphicx}
\newlength\replength
\setlength\replength{1.3pt}% HORIZONTAL DOT SEP
\newcommand\dotscale{.5}% SCALES DOT SIZE
\newcommand\sidebearing{.9pt}% DOT'S SIDEBEARING
\newsavebox\mydot
\newcommand\tdotfill[1][\repfrac]{\xleaders\hbox to \replength{%
  \smash{\raisebox{\arraystretch\dimexpr\ht\strutbox-.1ex\relax}%
    {\usebox{\mydot}}}}%
  \hfill}
\newcommand\tdotleft[1][\tabcolsep]{%
  \makebox[0pt][r]{\makebox[#1]{\tdotfill}}}
\newcommand\tdotright[1][\tabcolsep]{%
  \makebox[0pt][l]{\makebox[#1]{\tdotfill}}}
\newcommand\tabdotline[1][Q]{%
  \savebox\mydot{%
    \scalebox{\dotscale}{\kern-\sidebearing.\kern-\sidebearing}}%
  \ifx l#1\relax\tdotleft\tdotfill\else
  \ifx r#1\relax\tdotfill\tdotright\else
  \ifx \relax#1\relax\tdotfill\else
  \tdotleft\tdotfill\tdotright 
  \fi\fi\fi\mbox{}}
\newcommand\dotend{\unskip\kern\dimexpr\wd\mydot-\replength\relax
  \\[-\arraystretch\dimexpr\ht\strutbox+\dp\strutbox\relax]}
\begin{document}
\begin{minipage}[t][1in][t]{3in}
    Hello world!\\
    \begin{tabular}[t]{@{}rll@{}}
            \noalign{\hrule height 0.5pt}
        a & some & text \\
          \tabdotline[r] &  \tabdotline &\tabdotline[l] \dotend
        b & some & other text \\
          \tabdotline[r] &  \tabdotline &\tabdotline[l] \dotend
        b & some more & text \\
          \tabdotline[r] &  \tabdotline &\tabdotline[l] \dotend
    \end{tabular}%
\end{minipage}
\end{document}

enter image description here

6
  • Thanks, though this won’t align the dots to the edges, and also lines with different dot sizes won’t start at the same point. The question I have is rooted in micro typography. Does solve the problem of overshoot though.
    – codepoet
    Commented Sep 16, 2020 at 10:09
  • @reportaman Should not the use of \xleaders align the dots to the edges? And start at the same point? I contend that they do. The downside is that the dot spacing will vary slightly throughout the width of the tabular, depending on the individual column spacings and the value of \tabcolsep. Commented Sep 16, 2020 at 10:10
  • No, I just tested, bounding edges of dotted lines with different size don't align right below each other. This is most likely due to the different side-bearing size for dot glyph for different font size. The solution would be to remove left side bearing from the leftmost dot, and right side bearing from right most dot within the leaders somehow or making the box width extend by 2 side-bearings worth length before typesetting leaders in them.
    – codepoet
    Commented Sep 16, 2020 at 10:29
  • 1
    @reportaman You are right that sidebearings do play a role. I will see if I can adapt Commented Sep 16, 2020 at 10:33
  • Also, I wonder if we can have just one end-to-end xleaders box, like in a \noalign macro? That will ensure that there is even spacing from end-to-end. Currently, as you note, the spacing changes at the edges of cells. Also, sidebearings are at least extractable in XeLaTeX & LuaLaTeX.
    – codepoet
    Commented Sep 16, 2020 at 10:39
2

Here is what you can do with {NiceTabular} of nicematrix. That environment is similar to {tabular} (of array) but adds PGF/Tikz nodes under the rows, cells and columns of the array.

It's possible to use that nodes to draw dotted rules with Tikz.

\documentclass[notitlepage,letterpaper]{article}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}


\ExplSyntaxOn
\makeatletter
\NewDocumentCommand { \mydottedline } { }
  {
    \tl_gput_right:Nx \g_nicematrix_code_after_tl
      {
        \exp_not:N \tikz [dotted]
          \exp_not:N \draw (\int_use:N \c@iRow -| 1 ) 
                -- (\int_use:N \c@iRow -|\exp_not:N \int_eval:n { \c@jCol + 1 } ) ;
      }
  }
\makeatother
\ExplSyntaxOff  
  
\begin{minipage}[t][1in][t]{3in}
    Hello world!\\
    \begin{NiceTabular}[t]{@{}rll@{}}
        \noalign{\hrule height 0.5pt}
        a & some & text \\
            \mydottedline
        b & some & other text \\
            \mydottedline
        b & some more & text \\
            \mydottedline
    \end{NiceTabular}%
\end{minipage}

\end{document}

Output of the above code

1
  • Thanks; even though the question explicitly states no tikz based solutions, having it as a record here might benefit the broader community. Though am looking for a non tikz solution — some magic with Tex ‘xleaders’
    – codepoet
    Commented Sep 17, 2020 at 0:55
-2

https://tex.stackexchange.com/a/332124/197451

This should point you in the right direction

enter image description here

\documentclass{article}

\newcommand\fillin[1][3cm]{\makebox[#1]{\dotfill}}
\begin{document} 
Why appropriate, specify? \fillin\\ 


Why inappropriate, specify? \fillin[4cm]\\ 


Why appropriate, specify? \dotfill\\


Why inappropriate, specify? \fillin[2cm]
\end{document}
2
  • 1
    This does not solve the main problem of the question: \newcommand\fillin[1][3cm]{\makebox[#1]{\dotfill}} and \dotfill are pretty much same other than manually specified length. A solution would stretch the dots to the length of the table, which can vary. I had tried this before but could not find how to access length of the table from within table either.
    – codepoet
    Commented Sep 16, 2020 at 7:56
  • 2
    I think that your answer is off-topic.
    – Sebastiano
    Commented Sep 16, 2020 at 14:32

You must log in to answer this question.

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