[XeTeX] table indentation

Ross Moore ross at ics.mq.edu.au
Sun Nov 22 23:23:53 CET 2009


Hi Michiel,

On 23/11/2009, at 8:26 AM, Michiel Kamermans wrote:


> Getting part (2) to work sucked, to be honest, because I couldn't  
> figure out how to tell TeX to check the width of the generated  
> table without analysing aux files and writing something in pure TeX  
> (which I still find mystifyingly hard),

You just set the table inside a box, and measure it,
before inserting it onto the page (or doing something else).

In TeX primitives, the procedure is:

% in the preamble declare a box register
\newbox\testbox

%in the source, or within a command definition, do ...
   \setbox\testbox=\hbox{%
     \begin{tabular}... your table data ... \end{tabular}%
   }%  data is set within a box

Now the width of the box is read from the registers using ...
    \the\wd\testbox   % gives the width of the box
    \the\ht\testbox   % gives the height of the box
    \the\dp\testbox   % gives the depth of the box

You can look at these values or use them in conditional tests.

When you know it will fit, you can either put the box onto
the page, using  \box\testbox   (or \unbox\testbox  is sometimes
better, especially if it is only a little bit too wide).

Or if the box won't fit as it is, then just ignore it
and use {longtable}, or whatever other strategy is appropriate.


> so instead I just wrote a table width guestimator based on the fact  
> that I use Palatino Linotype as main font, and Kozuka Mincho Pro as  
> CJK font... most of the time. Since the conversion of table data is  
> fully deterministic, computing a width guess based on the table  
> properties was doable (and determining the font metrics for  
> palatino took a bit, but as a job was fairly simple). The  
> guestimator won't get the table width exactly right, but it's close  
> enough to what TeX ends up with, so it's reliable enough for  
> determining whether a table will be too wide in the resulting  
> document.

If you know its exact natural width, as given above, then you can
automate making minor adjustments, such as

   \addtolength{tabcolsep}{-2pt} % reduce space between columns
   \renewcommand{\arraystretch}{.9}  % reduces space between rows
   \small  %  or  \smaller  with AMSmath macros

>
> If the table is then still too wide without indentation,  
> intervention in the source material is required, but tables that  
> are still too wide if they get the full page width are typically  
> good examples of bad tables, so the source would have to be  
> adjusted then anyway.

You can make a lot of things fit by adjusting the spacing between
rows and columns, and/or a reduction in font sizes.

>
> So tables are pretty good, they don't really lead to awkwardly  
> spaced pages - regular text, on the other hand, seems to. There is  
> the occasional page that is so curiously vertically spaced that I  
> just go "but, what are you doing TeX, you can fit more lines of  
> text on that page easily, and I don't see any problems on the next  
> page if you relocate some lines from the next page's top paragraph  
> to this one...". However, that's not really the tool chain's fault,  
> since the source for those pages typically don't even involve  
> tables (it's usually near mostly text pags with short 2 or 4 item  
> lists wrapped in the "samepage" environments per set of two with  
> lots of text paragraphs around them).
>
> An example of this would be document page 77 (pdf page 91) in  
> http://grammar.nihongoresources.com/lib/exe/fetch.php? 
> media=an_introduction_to_japanese_-_syntax_grammar_language.pdf - I  
> have no idea why TeX did things that way.. In this case, I don't  
> see why it couldn't just move the next page's section heading, as  
> well as the entire first paragraph of text following that heading,  
> to the page before and space things out a little nicer.

Probably you don't have any \parskip  glue at the end of that paragraph.
If the table that follows is tied to that paragraph without any flexible
glue, then TeX cannot tell that it is desirable to break there.

So either you should put a blank line in the document source, before
your table environments, or else you can try making your {mytabular}
environments start with \par (before the \noindent, etc. )


> But that said, with the packages used, the chain works pretty well.
>
> - Mike


Hope this helps,

	Ross

------------------------------------------------------------------------
Ross Moore                                       ross at maths.mq.edu.au
Mathematics Department                           office: E7A-419
Macquarie University                             tel: +61 (0)2 9850 8955
Sydney, Australia  2109                          fax: +61 (0)2 9850 8114
------------------------------------------------------------------------





More information about the XeTeX mailing list