0

I wanted to check if Latex is an option for outputting nicely readable large tables in genetic papers. Well, I'm still hesitating if I should go along and invest more time in experimenting with it.

I have learned a lot in the last few days, and managed to get along with searching for Q&A in this site, but now I'm stuck at a seeminigly simple problem: why is my table shifted to the right, and why I cannot start it simply from the top of page. I already tried several tricks. The initial table was a longtable, then I chose the original tabular environment because it seems to be sufficient for the first tries. I managed to shrink it to fit on a page by the scalebox. This version seems to fit on a single page though, that's way the actual 1.0 scaling. The main problem is though:

The table itself was created from R with the xtable package, out of a data frame. And now the problem:

The table begins not at the top of the page and at the left margin, but somwhere in the middle of the page. And I cannot shift it to the proper position. What's the problem? How can I get it start "top and left"?

And here it is:

\documentclass[10pt,a4paper]{letter}
\usepackage{booktabs}
\usepackage{graphics}
\begin{document}

\clearpage

% latex table generated in R 3.2.2 by xtable 1.8-2 package
% Thu Feb 18 10:04:31 2016
\scalebox{1.0}{
\begin{tabular}[ht]{|l|l|r|r|l|}
  \hline
genetic risk score & trait & beta$\pm$SE & $\beta$ & p-value \\ 
  \hline
waist SNPs & waist circumference (cm) & 0.212$\pm$0.232 & 0.02 & 0.36 \\ 
   & visceral adipose tissue (l) & -0.019$\pm$0.028 & -0.01 & 0.49 \\ 
   & liver fat content (\%) & 0.394$\pm$0.14 & 0.09 & 0.005 \\ 
   & subcutaneous adipose tissue (l) & -0.07$\pm$0.047 & -0.02 & 0.13 \\ 
   & VAT to SCAT ratio & -0.001$\pm$0.003 & -0.00 & 0.85 \\ 
   & oGTT-derived insulin sensitivity index (AU) & 0.082$\pm$0.095 & 0.01 & 0.39 \\ 
   & fasting glucose (mmol/l) & -0.001$\pm$0.008 & -0.00 & 0.87 \\ 
   & glucose 120 min. (mmol/l) & -0.006$\pm$0.023 & -0.00 & 0.8 \\ 
   & cholesterol (mg/dl) & 0.089$\pm$0.45 & 0.00 & 0.84 \\ 
   & LDL cholesterol (mg/dl) & 0.335$\pm$0.391 & 0.02 & 0.39 \\ 
   & HDL cholesterol (mg/dl) & -0.01$\pm$0.152 & -0.00 & 0.95 \\ 
   & fasting triglycerides (mg/dl) & -1.114$\pm$1.658 & -0.01 & 0.5 \\ 
   \hline
hip SNPs & hip circumference (cm) & 0.228$\pm$0.381 & 0.01 & 0.55 \\ 
   & visceral adipose tissue (l) & -0.006$\pm$0.025 & -0.00 & 0.81 \\ 
     \hline
   & HDL cholesterol (mg/dl) & -0.108$\pm$0.073 & -0.03 & 0.14 \\ 
   & fasting triglycerides (mg/dl) & 0.802$\pm$0.795 & 0.02 & 0.31 \\ 
   \hline

   \end{tabular}
}

\end{document}
0
1

The problem lies somewhere else. The table is actually shifted only a few points to the right from the left margin (due to the scalebox command). The most of the apparent align is due to the table being too wide for the page and, therefore, overflowing the right margin. You can see it clearly when visualising the page margins. This can be done e.g. by the geometry package.

\usepackage[showframe]{geometry}

To get rid of the small space between the left margin and the table, add % right after the scalebox command:

\scalebox{1.0}{%

Since the table still overflows the right margin, you have to adjust the page width (or the table contents). For the first, use again e.g. the geometry package.

\usepackage[showframe,lines=50, top=2.5cm, left=2cm, right=2cm]{geometry}

Hope this answers your questions. It certainly worked for the example you provided.

Anyway, LaTeX may be difficult for beginners, however, it is worth the trouble :)

Edit:

Note that the geometry package affects the page default margins. Therefore, you may see the table shifting just by visualising the margins. although it may seem otherwise, the table is in either case aligned to the top left corner.

In fact, the default margins defined by the letter document class are rather wide. And the top margin especially.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.