在不同尺寸的横向页面上放置大型 tikz 图像时缺少浮动或页码

在不同尺寸的横向页面上放置大型 tikz 图像时缺少浮动或页码

我有一个包含大型 tikz 图像的文档。为了使用 pdflatex 显示此图像,我创建了宏来切换纸张大小,并且我使用该pdflscape包在 pdf 查看器中显示时旋转页面。使用这种技术,我能够在旋转的较大尺寸页面上根据需要显示图形,但下一页的页脚中缺少页码(并且没有手册\clearpage,文本不会正确跳转到下一页,而是继续通过页脚并进入后面的不可见深渊)。在图形后面的第二页,页码会返回。

下面的最小工作示例证明了这一现象:

\documentclass{article}
\usepackage{tikz}
\usepackage{pdflscape}

\usetikzlibrary{shapes}

% Macros for changing paper size
\newcommand{\startPaperSizeB}{%
  \begingroup
  \clearpage
  \setlength{\pdfpagewidth}{11in}
  \setlength{\pdfpageheight}{17in}
  \setlength{\paperwidth}{\pdfpagewidth}
  \setlength{\paperheight}{\pdfpageheight}
  \setlength{\oddsidemargin}{0pt}
  \setlength{\textwidth}{650pt}
  \setlength{\topmargin}{0pt}
  \setlength{\headheight}{0pt}
  \setlength{\headsep}{0pt}
  \setlength{\textheight}{1084pt}
  }

\newcommand{\stopPaperSizeB}{\endgroup \clearpage}

\begin{document}

Some text on the first page.

\startPaperSizeB
\begin{landscape}

\begin{figure}
  \centering
    \begin{tikzpicture}[]
    \node [draw, rectangle, minimum height=625pt, minimum width=1000pt] (1) {};
  \end{tikzpicture}  
  \caption{Caption for the large size figure}
\end{figure}

\end{landscape}
\stopPaperSizeB

Missing page number on this page?

\clearpage

Now the page number is back!

\end{document}

我最近问过一个非常相似的问题,除了我把图形从 MWE 中去掉了。这个问题已经得到解答,但在更大的横向页面上插入时,解决方案不起作用tikzpicture——相反,没有更大的横向页面,也没有图形——它们只是消失了。我收到了关于盒子过满的警告,但没有图形。下面的 MWE 演示了这一点:

\documentclass{article}
\usepackage{tikz}
\usepackage{pdflscape}

\usetikzlibrary{shapes}

% Macros for changing paper size
\newcommand{\startPaperSizeB}{%
  \setlength{\pdfpagewidth}{11in}
  \setlength{\pdfpageheight}{17in}
  \setlength{\paperwidth}{\pdfpagewidth}
  \setlength{\paperheight}{\pdfpageheight}
  \setlength{\oddsidemargin}{0pt}
  \setlength{\textwidth}{650pt}
  \setlength{\topmargin}{0pt}
  \setlength{\headheight}{0pt}
  \setlength{\headsep}{0pt}
  \setlength{\textheight}{1084pt}
  }

\newcommand{\stopPaperSizeB}{}

\begin{document}

Some text on the first page.

\begin{landscape}
\startPaperSizeB

\begin{figure}
  \centering
    \begin{tikzpicture}[]
    \node [draw, rectangle, minimum height=625pt, minimum width=1000pt] (1) {};
  \end{tikzpicture}  
  \caption{Caption for the large size figure}
\end{figure}

\stopPaperSizeB
\end{landscape}

The page number is here, but the figure is not.

\end{document}

如果矩形的尺寸足够小(例如缩小到 525 x 550),那么图形就会出现在文档末尾的页面上,尽管页面是正常大小,图形会超出页面。这让我尝试了软件包[H]中的选项float,这似乎让我更接近目标,但我仍然没有成功。有什么想法吗?

答案1

我找到了一个可接受的答案,即使用geometry包来调整文本区域的大小(geometry包本身不允许在文档中间更改纸张大小)。设置textwidthtextheight使用命令很重要(如果不使用包设置这些命令,并且在开始环境之前执行此操作\newgeometry会产生奇怪的效果。此外,必须在离开环境后调用。geometrylandscape\restoregeometrylandscape

下面的例子解决了页码问题以及消失的 tikz 图形问题。

\documentclass{article}
\usepackage{tikz}
\usepackage{pdflscape}
\usepackage[papersize={8.5in,11in}]{geometry}
\usepackage{lipsum}

\usetikzlibrary{shapes}

% Macros for changing paper size
\newcommand{\startBSizeLandscape}{%
  \newgeometry{textwidth=614pt, textheight=1084pt}
  \begin{landscape}
  \setlength{\pdfpagewidth}{11in}
  \setlength{\pdfpageheight}{17in}
  \setlength{\paperwidth}{\pdfpagewidth}
  \setlength{\paperheight}{\pdfpageheight}
  \setlength{\oddsidemargin}{0pt}
  \setlength{\evensidemargin}{0pt}
  \setlength{\marginparwidth}{0pt}
  \setlength{\topmargin}{0pt}
  \setlength{\headheight}{0pt}
  \setlength{\headsep}{0pt}
  }

\newcommand{\stopBSizeLandscape}{%
  \end{landscape}
  \restoregeometry
  }

\begin{document}

\lipsum

\startBSizeLandscape

\begin{figure}
  \centering
    \begin{tikzpicture}[]
    \node [draw, rectangle, minimum height=589pt, minimum width=1000pt] {};
  \end{tikzpicture}  
  \caption{Caption for the large size figure}
\end{figure}

\stopBSizeLandscape

\lipsum

\end{document}

编译此代码确实会产生警告: 'tmargin' and 'bmargin' result in NEGATIVE (-289.03001pt). 'height' should be shortened in length. 当然,降低文本高度确实可以避免出现此警告,但会生成框满警告。更好的解决方案是无警告。

相关内容