3

I’m trying to design the front cover of a book with tikz package. The following is my latex code:

\documentclass[b5paper,11pt]{article}
\usepackage{geometry}
\usepackage{tikz}
\begin{document}
\newgeometry{top=0pt,bottom=0pt,left=0pt,right=0pt}
\thispagestyle{empty}
\setlength\parindent{0pt}
\begin{tikzpicture}[color=white,line width=.1em,font=\fontsize{90}{90}\selectfont]
\filldraw[color=blue] (0,0) rectangle (\paperwidth,\paperheight);
\draw (.05\paperwidth,0) -- (.05\paperwidth,\paperheight);
\draw (0,.1\paperheight) -- (.05\paperwidth,.1\paperheight);
\draw (0,.3\paperheight) -- (.05\paperwidth,.3\paperheight);
\draw (0,.5\paperheight) -- (.05\paperwidth,.5\paperheight);
\draw (0,.7\paperheight) -- (.05\paperwidth,.7\paperheight);
\draw (0,.9\paperheight) -- (.05\paperwidth,.9\paperheight);
\node[draw,align=center] at (.8\paperwidth,.5\paperheight) {B\\O\\O\\K};
\end{tikzpicture}
\end{document}

But after compiling the latex code, except the front cover, I get a extra blank page before it. What is the problem with it?

2
  • Have you tried setting geometry in the preamble rather than starting a new geometry as soon as you start the document?
    – cfr
    Mar 30, 2014 at 3:31
  • It thinks the picture is too big but I'm not sure why.
    – cfr
    Mar 30, 2014 at 3:41

1 Answer 1

2

You rectangle larger than the paper by \pgflinewidth since the upper point for rectangle is at (\paperwidth,\paperheight). You can either

  1. use fill instead of filldraw\fill[color=blue,use as bounding box] (0,0) rectangle (\paperwidth,\paperheight);
  2. or use ($(\paperwidth,\paperheight)+(-\pgflinewidth,-\pgflinewidth)$) in the construction of rectangle. This needs calc library. → \filldraw[color=blue,use as bounding box] (0,0) rectangle ($(\paperwidth,\paperheight)+(-\pgflinewidth,-\pgflinewidth)$);

Also note that I have used the big blue rectangle as the bounding box.

Full code

\documentclass[b5paper,11pt]{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\newgeometry{top=0pt,bottom=0pt,left=0pt,right=0pt}
\thispagestyle{empty}
\setlength\parindent{0pt}
\begin{tikzpicture}[color=white,line width=.1em,font=\fontsize{90}{90}\selectfont]
\fill[color=blue,use as bounding box] (0,0) rectangle (\paperwidth,\paperheight);
%%\filldraw[color=blue,use as bounding box] (0,0) rectangle ($(\paperwidth,\paperheight)+(-\pgflinewidth,-\pgflinewidth)$);
\draw (.05\paperwidth,0) -- (.05\paperwidth,\paperheight);
\draw (0,.1\paperheight) -- (.05\paperwidth,.1\paperheight);
\draw (0,.3\paperheight) -- (.05\paperwidth,.3\paperheight);
\draw (0,.5\paperheight) -- (.05\paperwidth,.5\paperheight);
\draw (0,.7\paperheight) -- (.05\paperwidth,.7\paperheight);
\draw (0,.9\paperheight) -- (.05\paperwidth,.9\paperheight);
\node[draw,align=center] at (.8\paperwidth,.5\paperheight) {B\\O\\O\\K};
\end{tikzpicture}
\end{document}

enter image description here

A short version:

\documentclass[b5paper,11pt]{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\newgeometry{top=0pt,bottom=0pt,left=0pt,right=0pt}
\thispagestyle{empty}
\setlength\parindent{0pt}
\begin{tikzpicture}[color=white,line width=.1em,font=\fontsize{90}{90}\selectfont]
\filldraw[color=blue,use as bounding box] (0,0) rectangle ($(\paperwidth,\paperheight)+(-\pgflinewidth,-\pgflinewidth)$);

\foreach \x in {0.1,0.3,...,0.9}{
   \draw (0,\x\paperheight) -- (.05\paperwidth,\x\paperheight);
}
\draw (.05\paperwidth,0) -- (.05\paperwidth,\paperheight);
\node[draw,align=center] at (.8\paperwidth,.5\paperheight) {B\\O\\O\\K};
\end{tikzpicture}
\end{document}

If you don't want to use calc library, just use

(\paperwidth-\pgflinewidth,\paperheight-\pgflinewidth)

as noted by Torbjørn T.

2
  • You can do just (\paperwidth-\pgflinewidth,\paperheight-\pgflinewidth), no need for calc. Mar 30, 2014 at 7:10
  • @TorbjørnT. Good point. Some how, I am biased towards using calc. However, I have added a note in the answer. Thanks for the ping. :)
    – user11232
    Mar 30, 2014 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .