# Finding the current position on the PDF

I am trying to generate automated reports in R using knitr. There are a list of objects I need to print on the PDF and the size (rows, columns, length etc.) can vary. The problem is that when any of the list of objects starts from the middle of the page, it is possible that it will flow out of the page. So, I was wondering if there was a way to know where I am on the page, so that I can decide whether the next object should be printed on the same page, or I use \clearpage and start in the next page.

• – Claudio Fiandrino Apr 25 '13 at 9:58
• In LaTeX you usually put material like that in a floating environment such as a figure or table and let LaTeX find a good position for the float---it may even end up at a different page. Using labels and cross-referencing commands you can then properly cross-reference the float. To be honest, I can't remember when I needed a \clearpage. – user10274 Apr 25 '13 at 9:58
• That should be an answer I guess. I looked up on floating environments and I found out about a package called <code>float</code>, which I think will do the same thing you said. – Prateek Kulkarni Apr 25 '13 at 10:44
• Glad it helped. The next time you reply, make sure you address the recipient (using @recipient syntax). If you don't the recipient won't be notified. – user10274 Apr 25 '13 at 10:53
• @MarcvanDongen Thanks. There is one more thing. To create tables from R objects, I use xtable() function in R. It basically converts the R object to TeX format. That uses tabular instead of table. That means I need to wrap tabular with table (Or wrapping xtable() with table). Does that make sense? – Prateek Kulkarni Apr 25 '13 at 11:00

In LaTeX you usually put illustrations, graphics, and tables in a floating environment such as a figure or table and let LaTeX find a good position for the float---it may even end up at a different page.

You may have to get used to this approach but it is better because you don't have to worry about where to "put" the material for your floats.

Using labels and cross-referencing commands you can then properly cross-reference the float. To be honest, I can't remember when I needed a \clearpage.

The following is an example.

\documentclass{article}
% For creating paragraphs.
\usepackage{lipsum}
% For creating fancy tables.
\usepackage{booktabs}
\begin{document}
\lipsum[1-2]
\begin{table}[pth]% default positioning...
\begin{tabular}{ll}
\toprule
\\\bfseries First Name & \bfseries Surname
\\\midrule
Donald & Knuth
\\ Leslie & Lamport
\\\bottomrule
\end{tabular}
% Define a caption and a label for the table.
% I always put the label in the argument of the caption.
\caption{\label{tab:names}Names of famous {\TeX}nicians.}
\end{table}
% Cross-reference the table with the \ref command and the label.
Table~\ref{tab:names} lists the names of some famous {\TeX}nicians.
\lipsum[3-4]
\end{document}

• Is table a floating environment by default? – Prateek Kulkarni Apr 25 '13 at 11:23
• @PrateekKulkarni Yes. LaTeX has only two floating environments: table and figure. Additional packages may define their own floating environments. For example, the lstlistings package defines an environment for program listings. See this link if you want to define your own floating environment. – user10274 Apr 25 '13 at 12:16