Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like the whitespace between two items within a table to be filled with dots. Please consider the following picture to get the idea.

whitespace filled with dots

So far I tried to achieve this output with the following sequence.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[10pt]{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[!htbp]

\begin{tabular}{lrrr}
        \toprule
    Anzahl & Behandlungstyp & Einzelpreis & Gesamtpreis\\
        \midrule
    10\dotfill& Manuelle Therapie\dotfill & €32,63\dotfill & €326,30\\
    10\dotfill &Krankengymastik\dotfill &€26,93\dotfill &€269,30\\
        \bottomrule
    \end{tabular}

\end{table}

\end{document}

This, however, yields an unsatisfactory output, where undotted gaps are left over. output

How to achieve a continuous dotted line without white spaces like in the first picture?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

This is an ugly hack

\documentclass[10pt]{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[!htbp]

\begin{tabular}{l@{}r@{}lr}
 \toprule
    Anzahl \quad 
    & \multicolumn{1}{r@{}}{\hspace{1cm}Behandlungstyp}\quad  
    & Einzelpreis  
    & Gesamtpreis\\
 \midrule
    10\dotfill 
    & Manuelle Therapie\dotfill
    &\multicolumn{2}{@{}c}{€32,63\dotfill  €326,30}\\
    %%
    10\dotfill 
    & Krankengymastik\dotfill  
    &\multicolumn{2}{@{}c}{€26,93\dotfill €269,30}\\
 \bottomrule
\end{tabular}    
\end{table}

\end{document}

enter image description here

For the alignment as requested in the comment

\begin{tabular}{lcr@{}r@{}r}
 \toprule
    Anzahl
    &
    & Behandlungstyp  
    & \multicolumn{1}{@{\hspace{1em}}r@{}}{Einzelpreis}
    & \multicolumn{1}{@{\hspace{1em}}r}{Gesamtpreis}\\
 \midrule
    \multicolumn{3}{c@{}}{10\dotfill Manuelle Therapie}
    & \dotfill 32,63
    & \dotfill 326,30\\
    %%
    \multicolumn{3}{c@{}}{10\dotfill Krankengymastik}
    & \dotfill 26,93
    & \dotfill 269,30\\
 \bottomrule
\end{tabular}

enter image description here

share|improve this answer
    
If we could just manage to align the items correctly this hack would be easy to use. –  Ray Sep 21 '12 at 7:51
    
@Ray What is your idea of "aligning the items correctly"? Do you mean to align the header of the second column and entries in the second column (let us say on the left)? –  Guido Sep 21 '12 at 7:58
    
The alignment should actually be '{lrrr}'. If you take a look at the items of the second column, you will notice that they are everything else but right aligned - same applies for the items of the third column. The items of the first and last column are, however, correctly aligned. –  Ray Sep 21 '12 at 8:05

Here are two options:

  1. Manual using box length calculations:

    \documentclass{article}
    \usepackage{booktabs}% http://ctan.org/pkg/booktabs
    \newlength{\tmplenA}\newlength{\tmplenB}
    \begin{document}
    
    \begin{tabular}{lrrr}
      \toprule
      Anzahl & Behandlungstyp & Einzelpreis & Gesamtpreis\\
      \midrule
      \settowidth{\tmplenA}{Anzahl}\settowidth{\tmplenB}{10}\addtolength{\tmplenA}{-\tmplenB}%
      10\rlap{\makebox[\dimexpr\tmplenA+2\tabcolsep][l]{\dotfill}} & Manuelle Therapie 
      & \settowidth{\tmplenA}{Einzelpreis}\settowidth{\tmplenB}{€32,63}\addtolength{\tmplenA}{-\tmplenB}%
      \llap{\makebox[\dimexpr\tmplenA+2\tabcolsep][r]{\dotfill}}€32,63 
      & \settowidth{\tmplenA}{Gesamtpreis}\settowidth{\tmplenB}{€326,30}\addtolength{\tmplenA}{-\tmplenB}%
      \llap{\makebox[\dimexpr\tmplenA+2\tabcolsep][r]{\dotfill}}€326,30 \\
      \settowidth{\tmplenA}{Anzahl}\settowidth{\tmplenB}{10}\addtolength{\tmplenA}{-\tmplenB}%
      \settowidth{\tmplenB}{Manuelle Therapie}\addtolength{\tmplenA}{\tmplenB}%
      \settowidth{\tmplenB}{Krankengymastik}\addtolength{\tmplenA}{-\tmplenB}%
      10\rlap{\makebox[\dimexpr\tmplenA+2\tabcolsep][l]{\dotfill}} & Krankengymastik
      & \settowidth{\tmplenA}{Einzelpreis}\settowidth{\tmplenB}{€26,93}\addtolength{\tmplenA}{-\tmplenB}%
      \llap{\makebox[\dimexpr\tmplenA+2\tabcolsep][r]{\dotfill}}€26,93 
      & \settowidth{\tmplenA}{Gesamtpreis}\settowidth{\tmplenB}{€269,30}\addtolength{\tmplenA}{-\tmplenB}%
      \llap{\makebox[\dimexpr\tmplenA+2\tabcolsep][r]{\dotfill}}€269,30\\
      \bottomrule
    \end{tabular}
    
    \end{document}​
    
  2. Overwriting a \dotfill spanning the entire tabular width with white-background-boxed entries:

    \documentclass{article}
    \usepackage{booktabs}% http://ctan.org/pkg/booktabs
    \usepackage{xcolor}% http://ctan.org/pkg/xcolor
    \usepackage{array}% http://ctan.org/pkg/array
    \makeatletter
    \newcolumntype{L}{>{\begin{lrbox}{\@tempboxa}}l<{\end{lrbox}\colorbox{white}{\usebox{\@tempboxa}}}}
    \newcolumntype{R}{>{\begin{lrbox}{\@tempboxa}}r<{\end{lrbox}\colorbox{white}{\usebox{\@tempboxa}}}}
    \makeatother
    \newlength{\tmplenA}
    \setlength{\fboxrule}{0pt}\setlength{\fboxsep}{0pt}
    \begin{document}
    
    \settowidth{\tmplenA}{AnzahlManuelleTherapieEinzelpreisGesamtpreis\hspace*{6\tabcolsep}}
    \begin{tabular}{LRRR}
      \toprule
      Anzahl & Behandlungstyp & Einzelpreis & Gesamtpreis\\
      \midrule
      \rlap{\makebox[\tmplenA][l]{\dotfill}}\colorbox{white}{10} & Manuelle Therapie & €32,63 & €326,30 \\
      \rlap{\makebox[\tmplenA][l]{\dotfill}}\colorbox{white}{10} & Krankengymastik & €26,93 & €269,30\\
      \bottomrule
    \end{tabular}
    \end{document}​
    

Here's the output of both:

enter image description here

share|improve this answer
    
The first method works, but is very untransparent for me to be comprehensible - pardon this. The second one is indeed nice, but as you take a look at your output you will see that the dots are chopped. When I use my font they are even more chopped: cl.ly/image/2e3d2S1k3M3I Is there a possibility to make the first method easier, or make the second one more precise? Thank you. –  Ray Sep 21 '12 at 7:56

I believe that you need only the @{} separator and p{} columns with \dotfill or \hfill in the cells.

On the other hand, I lost the € symbol with your MWE because the lack of the fontspec package. For comparison, I included also the eurosym package for more official symbol (showed in the third column).

MWE

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[10pt]{article}
\usepackage{fontspec} % needed for the € symbol
\usepackage{eurosym} % another way to obtain the € symbol 
\usepackage{booktabs}
\begin{document}
\begin{table}[!htbp]
\begin{tabular}{p{.4\textwidth}@{}p{.2\textwidth}@{}p{.2\textwidth}@{}}
\toprule
Anzahl \hfill Behandlungstyp & \hfill Einzelpreis & \hfill Gesamtpreis\\
\midrule
10\dotfill  Manuelle Therapie & \dotfill\euro32,63 & \dotfill€326,30\\
10\dotfill  Krankengymastik & \dotfill\euro26,93 &\dotfill€269,30\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.