![如何制作带有虚线的 4 行 3 列表格](https://linux22.com/image/387135/%E5%A6%82%E4%BD%95%E5%88%B6%E4%BD%9C%E5%B8%A6%E6%9C%89%E8%99%9A%E7%BA%BF%E7%9A%84%204%20%E8%A1%8C%203%20%E5%88%97%E8%A1%A8%E6%A0%BC.png)
鉴于这虚线功能:
\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);}}
我想知道如何创建一个如下所示的表格:
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.
也就是说,表格居中,行与行之间有空间,第一列根据最大字符串动态调整大小,其他列大小固定但填满页面剩余空间,同时在两边留出小间隙。
我的第一次尝试从此开始:
\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}
但它遗漏了很多内容。本例中的行是固定宽度,而我希望改为动态宽度(可能设置最小尺寸)。
答案1
用一个tabularx
\dotfill
其中 -columns中有s X
:
\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}