Graphics, Figures & TablesPrinting a row only if it fits on one page

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mvastola
Posts: 2
Joined: Fri Mar 26, 2010 8:11 pm

Printing a row only if it fits on one page

Post by mvastola »

Hi,
I'm trying to design what I suppose is best described as a "work log" in LaTeX and I'm running into a bit of trouble I was hoping someone could help with..

Basically I'm looking for a way to print a block of text of arbitrary/variable length and underneath that print a table that creates horizontal lines that take up much of the rest of the page until there is no more room for them.

Here's a mockup of the LaTeX code I've written:

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\evensidemargin=0.25in     %
\oddsidemargin=0.25in      %
\hoffset=-0.75in
\textwidth=7.5in        %

\author{Michael Vastola}
\begin{document}
\begin{flushleft}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus lacinia enim non dolor condimentum interdum. Ut dapibus tristique dui non aliquam. Etiam nec consequat ipsum. Nam magna eros, pulvinar eget porta eu, tincidunt sed sem. Maecenas dapibus pulvinar risus, vel tempus metus ultrices at. Morbi mollis auctor varius. Sed sed nibh massa. In sollicitudin euismod mi sit amet vulputate. Aliquam pharetra eros at purus tincidunt placerat ut a massa. Proin at eros ligula.
\end{flushleft}

\begin{table}[b]
	\begin{tabular}{p{3.5in}p{0.5in}p{1in}p{0.5in}}
		\cline{1-1}
		\cline{3-3}
		Signature &
		&
		Date &
	\end{tabular}
\end{table}

\begin{tabular}{p{.5in}p{1in}p{4.5in}}
		\rule{.5in}{.5pt} &
		\rule{1in}{.5pt} &
		\rule{4.5in}{.5pt} \\
		\rule{.5in}{.5pt} &
		\rule{1in}{.5pt} &
		\rule{4.5in}{.5pt} \\
		\rule{.5in}{.5pt} &
		\rule{1in}{.5pt} &
		\rule{4.5in}{.5pt} \\
                %....repeat until there is no more room on page...
\end{tabular}
\end{document}
I'm kind of a n00b at LaTeX so any help would be greatly appreciated.

I suspect I might be able to do something with some logic commands, but I'm unsure how to loop something until the vertical position on the page exceeds a certain point (or even if I'm on the right track on thinking about this).

Thanks a lot in advance!
Mike

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Printing a row only if it fits on one page

Post by gmedina »

Hi,

in the following example code I defined a new command (I called it \maypage) with one mandatory argument; the command writes the contents of its argument and then fills the rest of the page with horizontal lines.

Code: Select all

\documentclass{article}
\usepackage{ifthen}

\newcommand\mypage[1]{%
  \setbox0=\vbox{#1}%
  \newdimen\heighta%
  \newdimen\heightb%
  \heighta=\ht0%
  \heightb=\textheight%
  \advance\heightb by -\heighta%
  \advance \heightb by -\baselineskip%
  \box0
  \whiledo{\heightb>0}
  {\par\noindent\hrulefill\advance \heightb by -\baselineskip}
}
\begin{document}

\mypage{text}

\mypage{text text text text text text text text text text text text text text text text text 
  text text text text text text text text text text text text text text text text text text text 
  text text text text text text text text text text text text text text text text text text text   
  text text text text text text text text}

\end{document}
Edit: now that I've read your post more carefully, perhaps defining \mypage to have two mandatory arguments would be better; here's the modified version and an example showing its use to reproduce what (I expect) you want:

Code: Select all

\documentclass{article}
\usepackage{ifthen}

\newcommand\mypage[2]{%
  \setbox0=\vbox{#1}%
  \newdimen\heighta%
  \newdimen\heightb%
  \heighta=\ht0%
  \heightb=\textheight%
  \advance\heightb by -\heighta%
  \advance \heightb by -\baselineskip%
  \box0
  \whiledo{\heightb>0}
  {\advance \heightb by -\baselineskip #2}
}
\begin{document}

\mypage{\begin{flushleft}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus lacinia enim non dolor condimentum interdum. Ut dapibus tristique dui non aliquam. Etiam nec consequat ipsum. Nam magna eros, pulvinar eget porta eu, tincidunt sed sem. Maecenas dapibus pulvinar risus, vel tempus metus ultrices at. Morbi mollis auctor varius. Sed sed nibh massa. In sollicitudin euismod mi sit amet vulputate. Aliquam pharetra eros at purus tincidunt placerat ut a massa. Proin at eros ligula.
\end{flushleft}
\leavevmode
   \begin{tabular}{p{2.56in}p{0.7in}p{1in}p{0.5in}}
      \cline{1-1}
      \cline{3-3}
      Signature &
      &
      Date &
   \end{tabular}
}{\noindent\rule{0.5in}{0.5pt}\hskip6pt\hrulefill\hskip6pt\rule{3in}{0.5pt}\par}

\end{document}
Anyway, I thing that you can use my examples as a starting point to achieve what you desire.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
mvastola
Posts: 2
Joined: Fri Mar 26, 2010 8:11 pm

Printing a row only if it fits on one page

Post by mvastola »

Thanks a lot for your help.
After a ton more searching I figured out something that works (though the sources I found seem to simultaneously advise against using it for reasons I don't understand), but here's what I ended up with that works.

Code: Select all

\usepackage{ifthen}

\whiledo{\pagetotal < \pagegoal}{
\begin{flushleft}
	\begin{spacing}{1.5}
		\begin{tabular}{p{.5in}p{1in}p{5.5in}}
			\rule{.5in}{.5pt} &
			\rule{1in}{.5pt} &
			\rule{5.5in}{.5pt} \\
		\end{tabular}
	\end{spacing}
\end{flushleft}
}
Post Reply