3

Given this dotted line functionality:

\newcommand{\adot}[1]{\tikz[baseline=(todotted.base)]{\node[inner sep=0pt,outer sep=0pt] (todotted) {#1};\draw[dotted, thick,inner sep=0pt,transform canvas={yshift=-2pt}] (todotted.south west) -- (todotted.south east);}}

I'm wondering how to sort of create a table that looks like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 
ea commodo consequat. Duis aute irure dolor in reprehenderit in 
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
mollit anim id est laborum.


    foo         .............    .............    .............      

    hello       .............    .............    .............      

    asdf        .............    .............    .............      

    something   .............    .............    .............      


Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 
ea commodo consequat. Duis aute irure dolor in reprehenderit in 
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
mollit anim id est laborum.

That is, the table is centered, and there is space between the rows, the first column is dynamically sized based on the largest string, while the others are fixed size but they fill up the remaining space of the page, while leaving a small gap on each side.

My first attempt starts at this:

\begin{center}
\begin{tabular}{ c c c }
  \adot{foo} & \adot{foo} & \adot{foo} \\
  \adot{foo} & \adot{foo} & \adot{foo} \\
  \adot{foo} & \adot{foo} & \adot{foo}
\end{tabular}
\end{center}

But it leaves a lot out. The rows are a fixed width in this example, which I would like to instead be dynamic width (with a minimum size set perhaps).

  • Yes, in my latex table the rows are accidentally fixed width. Instead, I would like for the 3 columns (with the dots in them) to be all the same width, but fill the width of the page (but leave some gap on the outside of the table). – Lance Pollard Dec 6 '18 at 6:44
4

Use a tabularx with \dotfills in the X-columns:

enter image description here

\documentclass{article}

\usepackage{lipsum}
\usepackage{tabularx,collcell}

\newcommand{\dotcell}[1]{%
  \makebox[\hsize]{#1}%
  \raisebox{-.2\normalbaselineskip}[0pt][0pt]{%
    \makebox[0pt][r]{\makebox[\hsize]{\dotfill}}}%
}

\begin{document}

\lipsum[1]

\begingroup
\medskip
\renewcommand{\arraystretch}{1.5}%
\noindent
\begin{tabularx}{\linewidth}{ l *{3}{>{\collectcell\dotcell}X<{\endcollectcell}} }
  foo       & foo &     &     \\
  hello     &     & goo &     \\
  asdf      &     &     & bar \\
  something & baz &     & 
\end{tabularx}
\medskip
\endgroup

\lipsum[2]

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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