\documentclass{article} \usepackage[mathbf]{euler} \usepackage{longtable} \usepackage{geometry} \geometry{head=14pt,hmargin=0.5in,vmargin=1.35in} %% Set up indexing headers and footer for fast lookup while %% flipping pages. \usepackage{fancyhdr} \pagestyle{fancy} \setlength{\headheight}{14.0pt} \renewcommand{\headrulewidth}{0pt} \lhead{\large\mathversion{bold}\firstmark} \rhead{\large\mathversion{bold}\botmark} \begin{document} %% This function is a utility to help the sprintf %% function keep the number of digits after the decimal %% place at the right level to come out to 9 digits in total %% both before and after the decimal point. {: def digs(x) if ("%0.8f" % x) =~ /[-+]?([0-9]*)\./ l = 10 - $1.length #$ l = (l > 0 ? l : 0) return l end return(0) end :} \def\tstrut{\rule[-1pt]{0pt}{11pt}} %% Set up the longtable environment by specifying the header for %% each page and the footer. \begin{longtable}[c]{c|llllll} \hline\hline \multicolumn{1}{c|}{\mathversion{bold}$x$}& \multicolumn{1}{c}{\mathversion{bold}$\sin(x)$}& \multicolumn{1}{c}{\mathversion{bold}$\cos(x)$}& \multicolumn{1}{c}{\mathversion{bold}$\tan(x)$}& \multicolumn{1}{c}{\mathversion{bold}$\cot(x)$}& \multicolumn{1}{c}{\mathversion{bold}$\sec(x)$}& \multicolumn{1}{c}{\mathversion{bold}$\csc(x)$}\\ \hline\hline \endhead \hline\hline \endfoot {: ## Set up variables needed for computing the values that go into ## the table, taking care to use ruby's BigDecimal class to ensure ## accuracy. The table is set up here to go from 0 to pi/2 in ## increments of step. require 'bigdecimal' require 'dms' DMS.precision = 0 step = DMS.new(0, 0, 30) one = BigDecimal("1.0") d0 = DMS.new(0) d90 = DMS.new(90) -:} %% Treat the first line of the table, for an x value of 0 specially %% by giving exact answers in symbolic form. {:= "\\multicolumn{1}{c|}{\\tstrut{\\mathversion{bold}\\mark{%s}$0$}}" % d0.to_tex :}& {:= "\\multicolumn{1}{c}{{$0$}}" :}& {:= "\\multicolumn{1}{c}{{$1$}}" :}& {:= "\\multicolumn{1}{c}{{$0$}}" :}& {:= "\\multicolumn{1}{c}{{$\\infty$}}" :}& {:= "\\multicolumn{1}{c}{{$1$}}" :}& {:= "\\multicolumn{1}{c}{{$\\infty$}}" :}\\ %% Here is the loop for the body of the table, which starts with %% x one step beyond 0 and pre-computes some of the functions {: x = d0 + step while (x < d90) do tanx = x.tan cotx = x.cotan secx = x.sec cscx = x.csc :} {: ## Here is where each line of the main body of the table is set. ## We use the digs function defined above to make sure that every ## column has the same number of significant digits for the functions ## that tend toward infinity. ## ## NB: I could write this comment as a LaTeX comment outside a code ## segment, but then it would end up in the generated LaTeX file, ## TrigTable.etx. Doing so made that file about 6MB in size; by ## putting the comments inside this ruby code block, the size was ## around 2MB. -:} \mark{{:= x.to_tex :}} \tstrut{:= "\\mathversion{bold}#{x.to_tex}" :}& {:= "$%0.8f$" % x.sin :}& {:= "$%0.8f$" % x.cos :}& {:= "$%0.*f$" % [ digs(tanx), tanx ] :}& {:= "$%0.*f$" % [ digs(cotx), cotx ] :}& {:= "$%0.*f$" % [ digs(secx), secx ] :}& {:= "$%0.*f$" % [ digs(cscx), cscx ] :}\\ %% Step and loop {: x += step end :} %% This causes a LaTeX error, but nonetheless gets the final line of %% the table squeezed onto the last page instead of on a page by %% itself. Uncomment if that's what you want. %{\enlargethispage{20pt}} %% Finally, treat the last row of the table for pi/2 specially %% by giving exact values symbolically. {:= "\\multicolumn{1}{c|}{\\mark{%s}\\mathversion{bold}%s}" % [d90.to_tex, d90.to_tex] :}& {:= "\\multicolumn{1}{c}{$1$}" :}& {:= "\\multicolumn{1}{c}{$0$}" :}& {:= "\\multicolumn{1}{c}{$\\infty$}" :}& {:= "\\multicolumn{1}{c}{$0$}" :}& {:= "\\multicolumn{1}{c}{$\\infty$}" :}& {:= "\\multicolumn{1}{c}{$1$}" :}\\ %% End the table and document---this version comes to 649 pages! \end{longtable} \end{document} % Take /that/ Charles Babbage!