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.
Asked
Active
Viewed 780 times
2
Prateek Kulkarni
- 123
1 Answers
2
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}
-
-
@PrateekKulkarni Yes. LaTeX has only two floating environments:
tableandfigure. Additional packages may define their own floating environments. For example, thelstlistingspackage defines an environment for program listings. See this link if you want to define your own floating environment. – Apr 25 '13 at 12:16
figureortableand 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. – Apr 25 '13 at 09:58float, which I think will do the same thing you said. – Prateek Kulkarni Apr 25 '13 at 10:44@recipientsyntax). If you don't the recipient won't be notified. – Apr 25 '13 at 10:53xtable()function in R. It basically converts the R object to TeX format. That usestabularinstead oftable. That means I need to wraptabularwithtable(Or wrappingxtable()withtable). Does that make sense? – Prateek Kulkarni Apr 25 '13 at 11:00tabularenvironment in a (floating)tableenvironment. – Apr 25 '13 at 11:06