如何确保两个独立文档具有相同的尺寸

如何确保两个独立文档具有相同的尺寸

我制作了两份standalone文档,它们的尺寸(页面大小)应该相同,但pdfinfo报告的页面大小(尺寸)却略有不同,我实在想不出为什么。这两份文档应该是打印件的正面和背面。

所包含的图形已被注释掉,因为它们不会影响文档尺寸,并且具有可重复性。

正面:(pdfinfo 报告尺寸为481.89 x 340.157 pts

\documentclass{standalone}
\pagestyle{empty}
\usepackage{tikz} 
\usepackage{ifthen} 
\usepackage{graphicx} 
\renewcommand*\ttdefault{lmvtt}
\usepackage[letterspace=120]{microtype}
\renewcommand{\familydefault}{\ttdefault}
\begin{document}
\begin{tikzpicture}
\fill[white] (-1,-1) rectangle (16,11);
\draw[thick] (0,0) rectangle (15,10);
%\node at (3.5,9.4) {\includegraphics[scale=0.25]{logo.pdf}};

\end{tikzpicture}
\end{document}

返回:(pdfinfo 报告大小为482.687 x 340.556 pts

\documentclass{standalone}
\pagestyle{empty}
\usepackage{tikz} 
\usepackage{ifthen} 
\usepackage{graphicx} 
\renewcommand*\ttdefault{lmvtt}
\usepackage[letterspace=120]{microtype}
\renewcommand{\familydefault}{\ttdefault}
\definecolor{blue}{HTML}{3c3475}
\begin{document}
\begin{tikzpicture}
\fill[blue] (-1,-1) rectangle (16,11);
\draw[gray] (7.5,-1) rectangle (7.5,11);
%\node at (3.5,7) {\includegraphics[scale=0.2]{dfp-logo.pdf}};
\end{tikzpicture}
\end{document}

答案1

从这个例子中可以看出原因:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}    
\begin{tikzpicture}
\draw [line width=1cm] (0,0) -- (1,0);
\draw [red] (0,0) -- (1,0);

\draw [blue,line cap=rect] (-0.5\pgflinewidth,0) -- (-0.5cm+0.5\pgflinewidth,0);
\end{tikzpicture}    
\end{document}

在此处输入图片描述

从蓝线可以看出,两侧的空白为 0.5 厘米,即黑线线宽的一半。即使使用标准, TikZ 似乎也会在边界框中为rect类型留出空间。line capbutt

因此,在您的例子中,第一个您只有

\fill[white] (-1,-1) rectangle (16,11);

而在第二个中,你还会\draw将路径移动到这个矩形的边缘。例如,当你这样做时

\draw[thick, white] (-1,-0.5) -- (16,-0.5);

因此,这将使边界框在左侧和右侧各延伸 0.4pt,与thick相对应line width=0.8pt。从 中pdfinfo,您会看到第二个比第一个宽约 0.8pt。

0.4pt 的高度差异同样来自

\draw[gray] (7.5,-1) rectangle (7.5,11);

在顶部和底部添加默认线宽的一半,即 0.4pt。

如果你将第二张图中有问题的线条改为

\draw[gray,line cap=rect] (7.5,-1cm+0.5\pgflinewidth) rectangle (7.5,11cm-0.5\pgflinewidth);
\draw[thick, white, line cap=rect] (-1cm+0.5\pgflinewidth,-0.5) -- (16cm-0.5\pgflinewidth,-0.5);
\draw[thick, white, line cap=rect] (-1cm+0.5\pgflinewidth,10.5) -- (16cm-0.5\pgflinewidth,10.5);

根据 ,两个 PDF 都变为 481.89 x 340.157 pts pdfinfo

答案2

我的评论作为答案:

你可以告诉 TiZ 的期望尺寸是带有选项的tikzpicture单个对象的尺寸。将此选项添加到两张图片中的矩形中,将使它们的尺寸均为 481.89 x 340.157 pts 。tikzpictureuse as bounding box\fillpdfinfo

正面代码:

\documentclass{standalone}
\pagestyle{empty}
\usepackage{tikz} 
\usepackage{ifthen} 
\usepackage{graphicx} 
\renewcommand*\ttdefault{lmvtt}
\usepackage[letterspace=120]{microtype}
\renewcommand{\familydefault}{\ttdefault}
\begin{document}
\begin{tikzpicture}
\fill[white,use as bounding box] (-1,-1) rectangle (16,11);
\draw[thick] (0,0) rectangle (15,10);
%\node at (3.5,9.4) {\includegraphics[scale=0.25]{logo.pdf}};
\node at (5.8,9.12) {for};

%% Distance between each line should be changed from 0.03 to 0.04.
\draw[thick, densely dotted] (6.1,9.02) -- (13.5,9.02);
\draw[thick] (0.03,8.63) -- (14.97,8.63);
\draw[thin] (0.03,8.55) -- (14.97,8.55);
\draw[thick] (0.03,7.9) -- (14.97,7.9);

% Labels
\node at (0.5,8.225) {Tid};
\node at (2,8.19) {Mandag};
\node at (4,8.19) {Tirsdag};
\node at (6,8.19) {Onsdag};
\node at (9,8.19) {Torsdag};
\node at (11,8.19) {Fredag};
\node at (13,8.19) {L\o{}rdag};
\node at (14.5,8.225) {Tid};
\def\bordertext{Skole- og tegnemateriel, kollegiehefter etc.}
\node[rotate=-90] at (15.3,4.4) {\bordertext};
\node[rotate=90]  at (-0.3,4.4) {\bordertext};

\foreach \x in {1,3,5,7,8,10,12,14}{
    \def\topyone{8.53}; \def\lowyone{7.87};
    \def\topytwo{7.93}; \def\lowytwo{2.05}; % 0.03
    \ifthenelse{\x=1\OR\x=14}{
        \draw[thick] (\x,\topyone) -- (\x,\topytwo); % Top dividers
        \draw[thick] (\x,\lowyone) -- (\x,\lowytwo);  % Lower divider
    }{
        \draw[thin] (\x,\topyone) -- (\x,\topytwo); % Top dividers
        \draw[thin] (\x,\lowyone) -- (\x,\lowytwo); % Lower dividers
    }
}
% horizontal lines
\foreach \y in {7.25,6.6,5.95,5.30,4.65,4,3.35,2.7,2.05}{
       \draw[thin] (0.03, \y) -- (0.97, \y);
       \draw[thin] (1.03, \y) -- (2.97, \y);
       \draw[thin] (3.03, \y) -- (4.97, \y);
       \draw[thin] (5.03, \y) -- (6.97, \y);
       \draw[thin] (8.03, \y) -- (11.97,\y);
       \draw[thin] (12.03,\y) -- (13.97,\y);
       \draw[thin] (14.03,\y) -- (14.97,\y);
       }
\draw[thick] (0.03,2.05) -- (14.97,2.05);
\end{tikzpicture}
\end{document}

返回代码:

\documentclass{standalone}
\pagestyle{empty}
\usepackage{tikz} 
\usepackage{ifthen} 
\usepackage{graphicx} 
\renewcommand*\ttdefault{lmvtt}
\usepackage[letterspace=120]{microtype}
\renewcommand{\familydefault}{\ttdefault}
\definecolor{blue}{HTML}{3c3475}
\begin{document}
\begin{tikzpicture}
\fill[blue,use as bounding box] (-1,-1) rectangle (16,11);
\draw[gray] (7.5,-1) rectangle (7.5,11);
\draw[thick, white] (-1,-0.5) -- (16,-0.5);
\draw[thick, white] (-1,10.5) -- (16,10.5);
%\node at (3.5,7) {\includegraphics[scale=0.2]{dfp-logo.pdf}};
%\node at (11.5,8) {\includegraphics[scale=0.18]{title.pdf}};
%\node at (11.7,1.5) {\includegraphics[scale=0.18]{nameplate-line-white.pdf}};
\end{tikzpicture}
\end{document}

答案3

我对 Torbjørn T. 的解释非常准确,没有什么可以补充的。不过,我想说的是,Ti 的创造者Z 提供了一个可以更简单地解决这个问题的方法:pgfinterruptboundingbox。您可以轻松确认,在您的这个例子中使用它时,边界框不会增加。

\documentclass{standalone}
\pagestyle{empty}
\usepackage{tikz} 
\usepackage{ifthen} 
\usepackage{graphicx} 
\renewcommand*\ttdefault{lmvtt}
\usepackage[letterspace=120]{microtype}
\renewcommand{\familydefault}{\ttdefault}
\definecolor{blue}{HTML}{3c3475}
\begin{document}
\begin{tikzpicture}
\fill[blue] (-1,-1) rectangle (16,11);
\begin{pgfinterruptboundingbox}
\draw[gray] (7.5,-1) rectangle (7.5,11);
\end{pgfinterruptboundingbox}
%\node at (3.5,7) {\includegraphics[scale=0.2]{dfp-logo.pdf}};
\end{tikzpicture}
\end{document}

请注意,此技巧在创建辅助路径(例如,交叉路口)的情况下特别有用。

相关内容