preview, problem with showing floats

Maybe it will interest someone ... The problem with floats option disappear, if to float environment is added position option h:

\documentclass{article}
    \usepackage{booktabs}
    \usepackage{siunitx}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}
    \begin{table}[h]% with added position option h works as desired
\begin{tabular}{c*{6}{S[table-number-alignment = center,
                                   table-figures-integer = 7]}
                }
\toprule
 0  & {1} &  {2} & {3} & {4} & {5} \\
\midrule
 1 & 11802316.16 & 10270230.14 &  210947.01 & 6716332.35 & 6808728.66 \\
 \bottomrule
\end{tabular}
    \end{table}
\end{document}

Why this help, I still not understand. Because other options t, b doesn't work.


Let me quote the TeXbook, bottom of page 254 and top of page 255.

The default output routine, \shipout\box255, illustrates one extreme in which nothing is put into the vertical list that is carried over to the next page. The other extreme is

\output={\unvbox255
  \ifnum\outputpenalty<10000 \penalty\outputpenalty\fi}

which ships nothing out and puts everything back onto the main vertical list. (The command \unvbox255 takes the completed page out of its box, and the command \penalty\outputpenalty reinserts the penalty at the chosen breakpoint.) This makes a seamless join between the completed page and the subsequent material, because TeX has still not discarded glue and penalties at the breakpoint when it invokes an \output routine; hence TeX will go back and reconsider the page break. If the \vsize hasn't changed, and if all insertions have been held in place, the same page break will be found; but it will be found much faster than before, because the vertical list has already been constructed—the paragraphing doesn't need to be done again. Of course, an output routine like this makes TeX spin its wheels endlessly, so it is of no use except as an example of an extreme case.

To prevent such looping, your output routine should always make progress of some sort whenever it comes into play. If you make a mistake, TeX may be able to help you diagnose the error, because a special loop-detection mechanism has been built in: There is an internal integer variable called \deadcycles, which is cleared to zero after every \shipout and increased by 1 just before every \output. Thus, \deadcycles keeps track of how many times an output routine has been initiated since the most recent \shipout, unless you change the value of \deadcycles yourself. There's also an integer parameter called \maxdeadcycles, which plain TeX sets to 25. If \deadcycles is greater than or equal to \maxdeadcycles when your output routine is about to be started (i.e., when \deadcycles is about to be increased), TeX issues an error message and performs the default output routine instead of yours.

LaTeX sets \maxdeadcycles to 100.

With a normal document consisting only of a table environment, nothing particular happens. However, preview works by throwing away everything but the chosen pieces, in this case the floats.

It does this using the standard mechanism, but now, being the default positioning of a float tbp, the output routine is called by \end{document} but ships out nothing, because nothing triggers flushing the float queues. So the \deadcycles mechanism enters in the scene; the float can never be positioned, but it is still there, so TeX tries again, failing in the same way.

No matter how high you set the value of \maxdeadcycles, the error will arrive nonetheless, maybe a bit later. At that point, the default output routine is used and the insertions are eventually shipped out.

Solutions: use [htp] as a positioning argument, or add some text outside the float, which will be thrown away, but will allow the float to be positioned.

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}

uncommented dummy text

\begin{table}[h]
\begin{tabular}{
  c
  *{6}{
    S[table-number-alignment = center,
      table-format=8.2
     ]
  }
}
\toprule
0  & {1} &  {2} & {3} & {4} & {5} \\
\midrule
1 & 11802316.16 & 10270230.14 &  210947.01 & 6716332.35 & 6808728.66 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

(I fixed the table specifications.)

On the other hand, you get the same result much more easily with standalone:

\documentclass[border=5]{standalone}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{
  c
  *{6}{
    S[table-number-alignment = center,
      table-format=8.2
     ]
  }
}
\toprule
0  & {1} &  {2} & {3} & {4} & {5} \\
\midrule
1 & 11802316.16 & 10270230.14 &  210947.01 & 6716332.35 & 6808728.66 \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

Tags:

Preview