# How can I make the size of the PDF equal to the of the chessboard?

I have this piece of LaTeX:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
% Source: http://tex.stackexchange.com/a/15278/5645

\usepackage{chessboard}
\storechessboardstyle{4x4}{maxfield=d4}

\begin{document}
\begin{preview}

% showmover shows which player is to move
\chessboard[style=4x4,setwhite={Qa1,Qd2},showmover=false]

\end{preview}
\end{document}


And I compile using pdflatex.

But the PDF document is too wide (just mark the image to see its width)

How can I make the width of the PDF equal to the of the chessboard?

-
You could also remove the extra whitespace in a separate step using pdfcrop. –  Lev Bishop Sep 11 '12 at 6:34

The problem is the blank lines in the preview environment. You'll get a tight box by removing them:

\begin{preview}
% showmover shows which player is to move
\chessboard[style=4x4,setwhite={Qa1,Qd2},showmover=false]
\end{preview}

-
The blank lines create a paragraph, so the output is \linewidth wide. Removing the lines will give you only an horizontal box with no added space. –  Martin Scharrer Sep 11 '12 at 6:32

## Case 1

standalone has an option border that you can use to specify the left, bottom, right, top borders. Negative values can also be used to trim.

\documentclass[preview,border={-8pt -8pt -18pt -18pt}]{standalone}
% Source: http://tex.stackexchange.com/a/15278/5645

\usepackage{chessboard}
\storechessboardstyle{4x4}{maxfield=d4}

\begin{document}
% showmover shows which player is to move
\chessboard[style=4x4,setwhite={Qa1,Qd2},showmover=false]
\end{document}


## Case 2

If you want to have equal borders or trimmed offset, just use one value border=-5pt for example.

\documentclass[preview,border=-5pt]{standalone}
% Source: http://tex.stackexchange.com/a/15278/5645

\usepackage{chessboard}
\storechessboardstyle{4x4}{maxfield=d4}

\begin{document}
% showmover shows which player is to move
\chessboard[style=4x4,setwhite={Qa1,Qd2},showmover=false]
\end{document}


Remarks: The red rectangles were added when I converted the PDF output to PNG. They are useful to show the edges of the outputs.

-