![使用 tikz 设计封面时出现额外的空白页](https://linux22.com/image/287314/%E4%BD%BF%E7%94%A8%20tikz%20%E8%AE%BE%E8%AE%A1%E5%B0%81%E9%9D%A2%E6%97%B6%E5%87%BA%E7%8E%B0%E9%A2%9D%E5%A4%96%E7%9A%84%E7%A9%BA%E7%99%BD%E9%A1%B5.png)
我正在尝试设计一本带包装的书的封面tikz
。以下是我的乳胶代码:
\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}
但是编译完 latex 代码后,除了封面之外,前面多了一个空白页。这是什么问题?
答案1
\pgflinewidth
矩形的上端点位于 , 因此矩形比纸张大(\paperwidth,\paperheight)
。您可以
- 使用
fill
代替filldraw
→\fill[color=blue,use as bounding box] (0,0) rectangle (\paperwidth,\paperheight);
- 或用于
($(\paperwidth,\paperheight)+(-\pgflinewidth,-\pgflinewidth)$)
矩形的构造。这需要calc
库。→\filldraw[color=blue,use as bounding box] (0,0) rectangle ($(\paperwidth,\paperheight)+(-\pgflinewidth,-\pgflinewidth)$);
还请注意,我使用大蓝色矩形作为边界框。
完整代码
\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}
简短版本:
\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}
如果你不想使用calc
库,只需使用
(\paperwidth-\pgflinewidth,\paperheight-\pgflinewidth)
正如 Torbjørn T 所指出的。