是否正确剪辑了 3D tikz 以适应调整框?

是否正确剪辑了 3D tikz 以适应调整框?

考虑以下 MWE:

\documentclass[%
12pt,
journal,
onecolumn,
twoside,
draftcls,
letterpaper,
]{IEEEtran}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{3d}
\usepackage{adjustbox}
\usepackage{setspace} %\singlespacing
\usepackage{caption}
\usepackage[nopar]{lipsum}
\usepackage{xstring}
% http://tex.stackexchange.com/a/26808/2595
\makeatletter
\def\unpacklipsum#1#2#3{%
  \count@=#1\relax
  \advance\count@\m@ne
  \def#3{}%
  \loop\ifnum\count@<#2\relax
    \advance\count@\@ne
    \edef#3{#3\csname lipsum@\romannumeral\count@\endcsname}%
  \repeat}
\makeatother
% http://tex.stackexchange.com/a/168754/2595
\def\loremnchars[#1]#2{%
  \unpacklipsum{#1}{#1}{\myunpacked}%
  \StrMid{\myunpacked}{1}{#2}% same as \StrLeft{\myunpacked}{#2}
}

\begin{document}

\loremnchars[1]{255} ...

\begin{center}
\singlespacing
\begin{adjustbox}{width=0.9\textwidth}
\def\angl{70}
\begin{tikzpicture}[
  x={({cos(\angl)*1cm},{sin(\angl)*1cm})},y={(1.0cm,0cm)},z={(0,1cm)},
  every node/.append style={
    %xslant=0.0,yslant=0.0,
    transform shape,
  },
]

  \tikzstyle{rr} = [draw,fill=gray,opacity=0.5];

%   \node[] (tt) at (33,22) {};    %L1
%   \clip (0,0) rectangle (16,27); %L2

  \begin{scope}[canvas is yx plane at z=0.0]
    \draw[rr] (0,0) rectangle (15,27);
    \node[draw,align=left,anchor=south west] at (3,3.5) {\loremnchars[6]{60} \\ \loremnchars[7]{60}};
  \end{scope}

  \begin{scope}[canvas is yx plane at z=2.0]
    \draw[rr] (0,0) rectangle (15,27);
    \node[] (tdrag) at (7,24) {};
    \begin{scope}[shift={(tdrag)},
    rotate=180,
    anchor=center,
    transform shape,
    ]
      \node[draw,align=left] {\loremnchars[2]{60} \\ \loremnchars[3]{60}};
    \end{scope}
  \end{scope}

  \begin{scope}[canvas is yx plane at z=4.0]
    \draw[rr] (0,0) rectangle (15,27);
    \node[draw,align=left,anchor=south west] at (3,5.5) {\loremnchars[8]{60} \\ \loremnchars[9]{60}};
  \end{scope}

\end{tikzpicture}
\end{adjustbox}
\captionof{figure}[short]{
A short message; \loremnchars[5]{255} ...
}
\label{fig:test}
\end{center}

\end{document}

当标记%L1%L2注释的行如在 MWE 中一样时,我会按预期在页面中得到图像(单击可获得全尺寸):

测试11

不幸的是,我有一堆像这样的节点%L1,它们位于 3D 范围之外,这会弄乱adjustbox边距计算。因此,由于我需要这些节点,我想 - 也许我可以剪辑而不删除这些节点。不幸的是,当我尝试这样做时 - 通过取消注释上面 MWE 中的%L1%L2行 - 然后我得到了一个混乱的剪辑,并且节点的影响仍然可见:

测试12

所以我的问题是 - 我该如何剪辑tikzpicture,以便节点%L1保留,但我仍然获得与第一个屏幕截图相同的边距和透视?

答案1

如果你有意,你可以使用pgfinterruptboundingbox

   \begin{pgfinterruptboundingbox}
   \node[] (tt) at (33,22) {};    %L1
   \end{pgfinterruptboundingbox}

完整代码:

\documentclass[%
12pt,
journal,
onecolumn,
twoside,
draftcls,
letterpaper,
]{IEEEtran}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{3d}
\usepackage{adjustbox}
\usepackage{setspace} %\singlespacing
\usepackage{caption}
\usepackage[nopar]{lipsum}
\usepackage{xstring}
% http://tex.stackexchange.com/a/26808/2595
\makeatletter
\def\unpacklipsum#1#2#3{%
  \count@=#1\relax
  \advance\count@\m@ne
  \def#3{}%
  \loop\ifnum\count@<#2\relax
    \advance\count@\@ne
    \edef#3{#3\csname lipsum@\romannumeral\count@\endcsname}%
  \repeat}
\makeatother
% http://tex.stackexchange.com/a/168754/2595
\def\loremnchars[#1]#2{%
  \unpacklipsum{#1}{#1}{\myunpacked}%
  \StrMid{\myunpacked}{1}{#2}% same as \StrLeft{\myunpacked}{#2}
}

\begin{document}

\loremnchars[1]{255} ...

\begin{center}
\singlespacing
\begin{adjustbox}{width=0.9\textwidth}
\def\angl{70}
\begin{tikzpicture}[
  x={({cos(\angl)*1cm},{sin(\angl)*1cm})},y={(1.0cm,0cm)},z={(0,1cm)},
  every node/.append style={
    %xslant=0.0,yslant=0.0,
    transform shape,
  },
]

  \tikzstyle{rr} = [draw,fill=gray,opacity=0.5];
   \begin{pgfinterruptboundingbox}
   \node[] (tt) at (33,22) {};    %L1
   \end{pgfinterruptboundingbox}
%   \clip (0,0) rectangle (16,27); %L2

  \begin{scope}[canvas is yx plane at z=0.0]
    \draw[rr] (0,0) rectangle (15,27);
    \node[draw,align=left,anchor=south west] at (3,3.5) {\loremnchars[6]{60} \\ \loremnchars[7]{60}};
  \end{scope}

  \begin{scope}[canvas is yx plane at z=2.0]
    \draw[rr] (0,0) rectangle (15,27);
    \node[] (tdrag) at (7,24) {};
    \begin{scope}[shift={(tdrag)},
    rotate=180,
    anchor=center,
    transform shape,
    ]
      \node[draw,align=left] {\loremnchars[2]{60} \\ \loremnchars[3]{60}};
    \end{scope}
  \end{scope}

  \begin{scope}[canvas is yx plane at z=4.0]
    \draw[rr] (0,0) rectangle (15,27);
    \node[draw,align=left,anchor=south west] at (3,5.5) {\loremnchars[8]{60} \\ \loremnchars[9]{60}};
  \end{scope}

\end{tikzpicture}
\end{adjustbox}
\captionof{figure}[short]{
A short message; \loremnchars[5]{255} ...
}
\label{fig:test}
\end{center}

\end{document}

在此处输入图片描述

但请记住,边界框不会调整到页面内,并且使用您提供的坐标L1(即(tt)),如果您在节点中放置任何内容(tt),它都会超出页面。

正如 percusse 所指出的,添加overlay选项具有相同的效果。

\node[overlay] (tt) at (33,22) {};    %L1

相关内容