创建一个用空行填充页面的表格

创建一个用空行填充页面的表格

我正在尝试为我们的实验室创建一份库存表,因此我需要一张大的空白表。除了\midrule&&&\\一遍又一遍地复制和粘贴之外,有没有更好的方法?

我希望看起来像这样,但自动重复空白单元格直到页面填满:

%Page layout here
\documentclass[letterpaper, 12pt,twocolumn]{article}
\usepackage[left= 2 cm, right=2 cm, top = 2 cm, bottom = 2 cm]{geometry}

%Font stuff here
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

%Goddamn tables.
\usepackage{booktabs} %Makes the pretty table based on wikibooks example

\begin{document}

\centering
{\large
\begin{tabular}{c|c|c|c}
\toprule
Date & User & Amount Used & Procedure\\
\phantom{2015-3-17} & \phantom{NAME} & (mg) &  \phantom{XXX3-33}\\
\midrule
&&&\\
\midrule
&&&\\
\midrule&&&\\
\midrule&&&\\
\midrule&&&\\
\bottomrule
\end{tabular}
}
\end{document}

注意:我只是使用 Booktabs 添加中间规则,可以将其删除。这只是墙上的剪贴板上的内容,您可以随意将其弄得丑陋不堪。我只是厌倦了与 Word 的地狱般的布局工具作斗争。

編輯:有这个答案在中间放置空白行,但我对代码的理解还不够,无法修改它来填充到页面的末尾。

答案1

大卫·卡莱尔 (David Carlisle) 已经帮助我找到了大部分解决方案,因此我想我应该发布它:

%Page layout here
\documentclass[letterpaper, 12pt,twocolumn]{article}
\usepackage[left= 1 cm, right=1 cm, top = 2 cm, bottom = 1 cm]{geometry}

\newlength\linefillheight % vertical distance between lines
\setlength\linefillheight{1cm}

\newlength\wcolone %first column width
\setlength\wcolone{\dimexpr.125\textwidth-4mm\relax}
\newlength\wcoltwo %second column width
\setlength\wcoltwo{\dimexpr.125\textwidth-4mm\relax}
\newlength\wcolthree % third column width
\setlength\wcolthree{\dimexpr.125\textwidth-4mm\relax}
\newlength\wcolfour % third column width
\setlength\wcolfour{\dimexpr.125\textwidth-4mm\relax}

\newcommand\linefill{\leavevmode
    \rule{\wcolone}{0.4pt}\hspace*{4mm}\rule{\wcoltwo}{0.4pt}\hspace*{4mm}\rule{\wcolthree}{0.4pt}\hspace*{4mm}\rule{\wcolfour}{0.4pt}}

\makeatletter
\def\fillwithlines#1{%
  \begingroup
  \ifhmode
    \par
  \fi
  \hrule height 0pt
  \nobreak
  \cleaders\hbox to \hsize{\hskip \@totalleftmargin
          \vrule height \linefillheight depth 0pt width 0pt
          \linefill} \vskip #1 \hbox{}%
  \endgroup}
\makeatother


\begin{document}

\noindent\begin{minipage}[c][1cm][t]{\textwidth}
\parbox{\dimexpr\wcolone+4mm\relax}{\textbf{\centering Date}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\textbf{\centering User}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\textbf{\centering Amount Used\\mg}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\textbf{\centering Procedure}}%
\end{minipage}

\fillwithlines{\dimexpr\textheight-1cm\relax}

\noindent\begin{minipage}[c][1cm][t]{\textwidth}
\parbox{\dimexpr\wcolone+4mm\relax}{\textbf{\centering Date}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\textbf{\centering User}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\textbf{\centering Amount Used\\mg}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\textbf{\centering Procedure}}%
\end{minipage}

\fillwithlines{\dimexpr\textheight-1cm\relax}
\end{document}

根据这个答案。但是,如果有人能帮忙的话,我希望能够将列标题居中并在中间画一条线。

一些小的调整:

\documentclass[letterpaper, 12pt,twocolumn]{article}
\usepackage[left= 1 cm, right=1 cm, top = 2 cm, bottom = 1 cm]{geometry}

\newlength\linefillheight % vertical distance between lines
\setlength\linefillheight{1cm}

\newlength\wcolone %first column width
\setlength\wcolone{\dimexpr.125\textwidth-4mm-1.25pt\relax}
\newlength\wcoltwo %second column width
\setlength\wcoltwo{\dimexpr.125\textwidth-4mm-1.25pt\relax}
\newlength\wcolthree % third column width
\setlength\wcolthree{\dimexpr.125\textwidth-4mm-1.25pt\relax}
\newlength\wcolfour % third column width
\setlength\wcolfour{\dimexpr.125\textwidth-4mm-1.25pt\relax}

\newcommand\linefill{\leavevmode
    \rule{\wcolone}{0.4pt}\hspace*{4mm}\rule{\wcoltwo}{0.4pt}\hspace*{4mm}\rule{\wcolthree}{0.4pt}\hspace*{4mm}\rule{\wcolfour}{0.4pt}}

\makeatletter
\def\fillwithlines#1{%
  \begingroup
    \par
  \hrule height 0pt
  \nobreak
  \cleaders\hbox to \hsize{%
          \vrule height \linefillheight depth 0pt width 0pt
          \hss\linefill\hss} \vskip #1 \hbox{}%
  \endgroup}
\makeatother\showoutput

\setlength\columnseprule{1pt}

\begin{document}


\noindent\begin{minipage}[c][1cm][t]{\linewidth}
\parbox{\dimexpr\wcolone+4mm\relax}{\centering\textbf{Date}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\centering\textbf{User}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\centering\textbf{Amount Used\\mg}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\centering\textbf{Procedure}}%
\end{minipage}

\fillwithlines{\dimexpr\textheight-1cm\relax}

\noindent\begin{minipage}[c][1cm][t]{\linewidth}
\parbox{\dimexpr\wcolone+4mm\relax}{\centering\textbf{Date}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\centering\textbf{User}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\centering\textbf{Amount Used\\mg}}%
\parbox{\dimexpr\wcoltwo+4mm\relax}{\centering\textbf{Procedure}}%
\end{minipage}

\fillwithlines{\dimexpr\textheight-1cm\relax}
\end{document}

在聊天中您说您想要有 7 个标题的单列......

\documentclass[letterpaper, 12pt]{article}
\usepackage[left= 1 cm, right=1 cm, top = 2 cm, bottom = 1 cm]{geometry}

\newlength\linefillheight % vertical distance between lines
\setlength\linefillheight{1cm}
\usepackage[T1]{fontenc}

\newcommand\linefill{\hspace{\stretch{.5}}%
    \rule{.1\textwidth}{0.4pt}\hfill
    \rule{.1\textwidth}{0.4pt}\hfill
    \rule{.1\textwidth}{0.4pt}\hfill
    \rule{.1\textwidth}{0.4pt}\hfill
    \rule{.1\textwidth}{0.4pt}\hfill
    \rule{.1\textwidth}{0.4pt}\hfill
    \rule{.1\textwidth}{0.4pt}\hspace{\stretch{.5}}%
}

\makeatletter
\def\fillwithlines#1{%
  \begingroup
    \par
  \hrule height 0pt
  \nobreak
  \cleaders\hbox to \hsize{%
          \vrule height \linefillheight depth 0pt width 0pt
          \linefill} \vskip #1 \hbox{}%
  \endgroup}
\makeatother

\setlength\columnseprule{1pt}

\begin{document}


\noindent\begin{minipage}[c][1cm][t]{\linewidth}
\parbox[t]{\dimexpr\linewidth/7\relax}{\centering\textbf{Date}}%
\parbox[t]{\dimexpr\linewidth/7\relax}{\centering\textbf{User}}%
\parbox[t]{\dimexpr\linewidth/7\relax}{\centering\textbf{Amount Used\\mg}}%
\parbox[t]{\dimexpr\linewidth/7\relax}{\centering\textbf{Procedure}}%
\parbox[t]{\dimexpr\linewidth/7\relax}{\centering\textbf{User}}%
\parbox[t]{\dimexpr\linewidth/7\relax}{\centering\textbf{Amount Used\\mg}}%
\parbox[t]{\dimexpr\linewidth/7\relax}{\centering\textbf{Procedure}}%
\end{minipage}

\fillwithlines{\dimexpr\textheight-1cm\relax}
\end{document}

相关内容