Tikz 外部化并放置与图片重叠的标题

Tikz 外部化并放置与图片重叠的标题

原始问题

我在文档中有一些大的“香蕉形”图片。因此图片填满了整个页面,而“实际图片”(即非空白区域)却没有。我使用类似于以下的 tikz 在图片的空白处放置了一个标题此解决方案

图片本身是一张 tikz 图片,而且相当大,所以我使用外部化来减少编译时间。

一切都很顺利,直到我在标题中放置了一个引用。这是一个 MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{rotating}
\usetikzlibrary{external}
\tikzexternalize[up to date check=md5]
\begin{document}
\begin{sidewaysfigure}
\tikzexternalenable
\begin{tikzpicture}
\filldraw [blue] (0,0) -- +(0,15) -- (21,15) -- (21,5) -- (14,5) -- (12,0) -- cycle;
\draw (current bounding box.south east) node[anchor=south east, text width = 5cm]{\caption{An ugly blue figure as described in more detail in section \ref{sec:bluefig}. \label{pic:bluefig}}};
\end{tikzpicture}
\tikzexternaldisable
\end{sidewaysfigure}
\section{Bluefigures} \label{sec:bluefig}
Here is the description of the blue figure. The picture is in figure \ref{pic:bluefig}.
\end{document}

图片已正确生成并外化,但显然无法再将正确的引用放入图片中,因为标题是 pdf 文件的一部分,而不再是 tex 文件的一部分。

我发现了一些其他的线索:这里这里在 Stackexchange 上,但在这些情况下,标题像往常一样位于图片下方,因此它们没有帮助。

我试图嵌套 tikzpicture 环境,以便只将内部 tikzpicture 外部化,但除此之外不好的做法它没有起作用,我遇到了各种“未定义的控制序列”。此外,我尝试将图形包含在

\includegraphics{filename.tikz}

但这在 tikzpicture 环境中不起作用。在这种情况下,编译器会抱怨未知的文件扩展名 .tikz。

现在我没什么主意了,如果有人能帮助我,我会很高兴。(我是否也应该发布不起作用的解决方案的 MWE?)


第一次尝试解决

根据 Ignasi 的提议,我试图找出是什么弄乱了覆盖图中的坐标。我认为外部化以某种方式阻止了 tikz 记住坐标。以下 MWE 在没有外部化的情况下使用覆盖和记住图片完美运行。一旦你取消注释外部化行,事情就会变得一团糟,我最终得到一个错误“没有已知名为角落的形状”。

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{positioning}
\usepackage{rotating}
\usetikzlibrary{external}
%\tikzexternalize[up to date check=md5]
\begin{document}
\begin{sidewaysfigure}
%\tikzexternalenable
\begin{tikzpicture}[remember picture]
\filldraw [blue] (0,0) -- +(0,15) -- (21,15) -- (21,5) -- (14,5) -- (12,0) -- cycle;
\draw [thick,black] (0,0) -- (21,0) -- (21,15);
\node (corner) at (current bounding box.south east){};
\end{tikzpicture}
%\tikzexternaldisable
\begin{tikzpicture}[overlay, remember picture]
\node [draw] at (corner) [anchor=south east,text width = 4cm, align=justify]%
 {\caption{The caption with reference to \ref{sec:bluefig} \label{pic:bluefig}}};
\end{tikzpicture}
\end{sidewaysfigure}
\section{Bluefigures} \label{sec:bluefig}
Here is the description of the blue figure. The picture is in 
     figure \ref{pic:bluefig}.
\end{document}

答案1

如果我没记错的话,您会在外部文件中发现未定义的引用,这会导致生成的文档包含通常的“??”而不是正确的节号。这似乎是唯一的问题,而覆盖问题只是试图找到解决方案,对吗?

对于这个问题,我有两个答案。


第一个答案是:等待下一个版本的externallib,因为它附带了完全自动化的错误修复。该externallib 随 PGF 一起提供,因此如果您是高级用户,则可以安装 PGF 的不稳定版本。该externallib 的副本也随附pgfplots(如果您写\usepackage{pgfplots}\usepgfplotslibrary{external}而不是\usetikzlibrary{external}),并且 的发布pgfplots计划于 2016 年 1 月的第一周发布。


第二个答案是:如果你打开.log文件,你会发现一些信息

LaTeX Warning: Reference `sec:bluefig' in external picture `PP-figure0' could not be resolved on input line 12.
This is because the PP.aux file is not accessable in this context, you will need to issue the externalize command
   pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "PP-figure0" "\def \tikzexternalrealjob {PP}\input {PP}"
manually.

“PP”是因为我的主文件名为“PP.tex”(在您的计算机上它可能有不同的名称)。

因此,第二个答案是:按照文件中显示的方式执行建议的命令行.log。在我的例子中,这是

pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "PP-figure0" "\def \tikzexternalrealjob {PP}\input {PP}"

现在,如果您重新编译主文档(在我的情况下是 PP.tex),则引用就被解析了。

external如果您拥有正确版本的lib(它将在本文发布后的几天内成为 pgfplots 稳定版本的一部分),那么这个“第二个答案”就不再需要了。


还有第三种解决方案,但前提是您是 Linux 下的高级用户。在这种情况下,您可以使用\tikzexternalize[mode=list and make]并使用make -f PP.makefile来编译外部图形(PP.tex 是主 tex 文件的名称)。这不会遇到这里的问题,可以直接工作。

答案2

如果您想caption在当前页面上写入一个固定点,您也可以使用TikZ它及其选项remember pictureoverlay。外部 tikz 图形仍然是外部的,但相应的标题写入实际文档中。

主要问题似乎是,作为一个景观页面,所有的引用都是错误的,所以经过一些测试后我可以这样做:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{positioning}
\usepackage{rotating}
\usetikzlibrary{external}
\tikzexternalize[up to date check=md5]
\begin{document}
\begin{sidewaysfigure}
\tikzexternalenable
\begin{tikzpicture}
\filldraw [blue] (0,0) -- +(0,15) -- (21,15) -- (21,5) -- (14,5) -- (12,0) -- cycle;
\end{tikzpicture}
\tikzexternaldisable
\begin{tikzpicture}[overlay, remember picture]
\node[text width = 5cm, draw, below right=1cm and 4cm of current page.south east] {%
    \caption{An ugly blue figure as described in more detail
           in section \ref{sec:bluefig}. \label{pic:bluefig}}};
\end{tikzpicture}
\end{sidewaysfigure}
\section{Bluefigures} \label{sec:bluefig}
Here is the description of the blue figure. The picture is in 
     figure \ref{pic:bluefig}.
\end{document}

在此处输入图片描述

相关内容