Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to use the geometry package to auto-crop the output of my LaTeX (so that it looks bigger on-screen as I'm editing). I have found a way to remove the margins completely and brutally:

\geometry{paperwidth=\textwidth,  paperheight = \textheight, margin=0cm}

However, I'd like to be somewhat more gentle. I tried the following, but it does not work:

\geometry{paperwidth=\textwidth + 1cm,  paperheight = \textheight+1cm, margin=1cm}

The reason is that arithmetic does not work inside these arguments. (LaTeX doesn't seem smart enough to do the addition).

What is the correct way to achieve this effect?

share|improve this question

3 Answers 3

up vote 13 down vote accepted

It works if you load the calc package.

\documentclass{article}

\usepackage{calc}

\usepackage{geometry}

\geometry{paperwidth=\textwidth+1cm,paperheight=\textheight+1cm, margin=1cm}

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\end{document}
share|improve this answer
    
This works wonderfully! Thank you! –  user21952-is-a-great-name Jul 31 '12 at 19:08

\dimexpr allows for expression-like addition/subtraction of dimensions:

\usepackage{geometry}% http://ctan.org/pkg/geometry
\geometry{
  paperwidth=\dimexpr\textwidth + 1cm\relax,
  paperheight=\dimexpr\textheight+1cm\relax, 
  margin=1cm}

calc automates this process through a redefinition of the length/dimension-related macro (\setlength, \addtolength, etc.).

share|improve this answer
    
Thank you! Apparently, I need another two reputation points to vote up, but I'm sure others will do it for me. –  user21952-is-a-great-name Jul 31 '12 at 19:10
    
@user21952-is-a-great-name You should be able to upvote soon enough. :-) –  lockstep Jul 31 '12 at 19:13
    
Just for information for those who do know it that division by floating point number is not allowed in , for example, \dimexpr\textwidth/3.14\relax. –  cyanide-based food Jul 31 '12 at 20:04
    
@HiggsBoson: Perhaps, but multiplication is fine: 0.3183\textwidth where 0.3183 ~ 1/π. –  Werner Jul 31 '12 at 20:12
    
@Werner: Yes. I agree. But fp is more expressive. :-) –  cyanide-based food Jul 31 '12 at 20:15

\dimexpr...\relax is not flexible enough because you cannot do division by a floating point number. \dimexpr\textwidth/3.141592654\relax, for example, is not possible!

That is why I prefer using the fp package because it can do any calculation.

\documentclass{article}
\usepackage[nomessages]{fp}

\FPeval{Width}{round(pow(0.5,2)*10*sin(pi/2):3)}% $10\sqrt(2)$ in 3 digits
%     after decimal point
\FPeval{Height}{round(pow(0.5,3)*10+cos(pi/2):3)}% $10\sqrt(3)$ in 3 digits
%    after decimal point

\usepackage
[
    paperwidth=\Width cm,
    paperheight=\Height cm,
]
{geometry}

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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