如何正确旋转 Tikz 节点组合而不旋转其标签文本?

如何正确旋转 Tikz 节点组合而不旋转其标签文本?

我见过如何让 TikZ 中的标签锚点受到旋转的影响而不旋转文本本身?;但这个问题似乎没有回答我的问题,所以我就继续说吧。

通过下面的 MWE,我得到了我想要的节点图:

测试51.png

如果我取消注释rotate=180anchor=center,我会得到下面的内容 - 标签中的文本没有像我想要的那样旋转,这是件好事,但除此之外,构图还是很混乱:

测试52.png

最后,如果我还启用/取消注释transform shape- 某些元素的构图会更好,而其他元素的构图会更差,但现在标签中的文本也会旋转,这是我不想要的:

测试53.png

所以问题是 - 有没有办法正确旋转整个构图,并且不旋转节点中的文本?我想要的输出,在 GIMP 中伪造:

test54-gimp.png

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}

\makeatletter
% https://tex.stackexchange.com/a/47709/2595
\tikzset{
  fitting node/.style={
    inner sep=0pt,
    fill=none,
    draw=none,
    reset transform,
    fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
  },
  reset transform/.code={\pgftransformreset},
}
\makeatother

\begin{tikzpicture}

\tikzstyle{drc} = [draw, rectangle, line width=1pt, align=center]
\tikzstyle{arr_edge} = [>=latex,->, line width=1pt]

\node[] (tdrag3) at (27.5,1.5) {};
\begin{scope}[shift={(tdrag3)},
%rotate=180,
%anchor=center,
%transform shape,
]
\node[drc,anchor=south west] (nd01) at (0,0) {Some \\ Words};

\node[drc,anchor=south] (nd02) at (3.5,2) {Some Terms};
\node[drc] (nd03) [above=0pt of nd02] {Something};
\node[drc] (nd04) [above=0pt of nd03] {Some Notions \\ Emulation \\ (Next)};

\draw[drc] (5.5,1.5) rectangle (12,5.5) node[fitting node] (nd05) {};
\node[drc,anchor=south,minimum width=6cm,minimum height=0.8cm] (nd06) [above=5pt of nd05.south] {Generic Definition Terms};
\node[drc] (nd07) [above=5pt of nd06.north east,anchor=south east] {Tests \\ (Conversion, Exchange, etc.)};

\draw[drc] let \p1=(nd06.north west), \p2=(nd07.south west), \p3=($(nd07.north west)+(-5pt,5pt)$), \p4=($(nd07.north east)+(0,5pt)$) in (\x1,\y2) -| (\x3,\y3) to node[above left=2pt and -2em]{Plain access} (\x4,\y4) -- ++(0,0.8cm) -| (\x1,\y2);
\node[align=center] (nd05titl) [below=2pt of nd05.north,anchor=north] {Generic Definition};

\draw[drc] (-0.5,6) rectangle (7.5,9) node[fitting node] (nd08) {};
\node[drc] (nd09) [above right=0pt of nd08.south east, anchor=south east] {Generic List Terms\\Word\ Number\ Variable\ Constant} ;
\draw let \p1=(nd01.center), \p2=(nd09.north) in node[drc] (nd10) at (\x1,\y2) [below=0pt,anchor=north] {Some Terms};
\node[drc] (nd11) [above=0pt of nd10.north,anchor=south] {More Than\\Interesting};
\node[drc] (nd12) [above=0pt of nd09.north,anchor=south] {Generic\\List One};
\node[align=center] (nd13) [below=2pt of nd08.north,anchor=north] {Another List};

\draw[arr_edge] (nd01) -- (nd10);
\draw[arr_edge] (nd11) -- (nd12);
\draw[arr_edge] (nd09) -| (nd05);
% wrap in calc $$ for tikzedt
\draw[arr_edge] (nd04) |- ($(nd05.north west)-(10pt,10pt)$) -- ($(nd05.south west)-(10pt,7.5pt)$) -| ($(nd06.south west)+(10pt,0)$);

\end{scope}

\end{tikzpicture}

\end{document}

答案1

好的,这里有一个修复 - 对于半修复,使用add referencefitting nodeR样式(按照在 3D tikz 中将线计算与拟合节点连接起来?rotate),似乎用和修复了节点的布局transform shape——我现在只需要帮助让文本在这种情况下不旋转(见下文);这是图像:

测试55.png

然后,感谢#168052 引用 lasttikznode 的内容并将其覆盖在节点上,我发现可以实现一个节点样式,其中包turn中的环境rotating可用于仅旋转节点内容框,作为单独的样式实现rotnt;然后drc节点样式可以简单地继承它 - 并且节点代码中唯一的内联更改是使用来设置无样式节点的样式rotnt,这样它们也会旋转。最后,我得到了所需的图像:

测试56.png

...代码如下:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{rotating} %tlmgr install rotating
\newbox\lastnodebox

\begin{document}

\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}

\begin{tikzpicture}
% https://tex.stackexchange.com/a/168052/2595
\tikzstyle{rotnt} = [
execute at begin node=\begin{turn}{180}\global\setbox\lastnodebox\hbox\bgroup,
execute at end node=\egroup\copy\lastnodebox\end{turn},
]
\tikzstyle{drc} = [draw, rectangle, line width=1pt, align=center, rotnt]
\tikzstyle{arr_edge} = [>=latex,->, line width=1pt]
%
%https://tex.stackexchange.com/a/47797/2595
\tikzset{add reference/.style={insert path={%
  coordinate [pos=0,xshift=-0.5\pgflinewidth,yshift=-0.5\pgflinewidth] (#1 south west)
  coordinate [pos=1,xshift=0.5\pgflinewidth,yshift=0.5\pgflinewidth]   (#1 north east)
  coordinate [pos=.5] (#1 center)
  (#1 south west |- #1 north east)     coordinate (#1 north west)
  (#1 center     |- #1 north east)     coordinate (#1 north)
  (#1 center     |- #1 south west)     coordinate (#1 south)
  (#1 south west -| #1 north east)     coordinate (#1 south east)
  (#1 center     -| #1 south west)     coordinate (#1 west)
  (#1 center     -| #1 north east)     coordinate (#1 east)
}}}
% https://tex.stackexchange.com/questions/167825/connecting-line-calculations-
% now fitting node must orient to rectangle coordinate for 3D:
\tikzset{
  fitting nodeR/.style={
    inner sep=0pt,
    fill=none,
    draw=none,%red, % for debug
    fit={(#1 south west) (#1 north east)},
  },
}
%
\node[] (tdrag3) at (27.5,1.5) {};
\begin{scope}[shift={(tdrag3)},
rotate=180,
anchor=center,
transform shape,
]
\node[drc,anchor=south west] (nd01) at (0,0) {Some \\ Words};

\node[drc,anchor=south] (nd02) at (3.5,2) {Some Terms};
\node[drc] (nd03) [above=0pt of nd02] {Something};
\node[drc] (nd04) [above=0pt of nd03] {Some Notions \\ Emulation \\ (Next)};

\draw[drc] (5.5,1.5) rectangle (12,5.5) [add reference=R1] node[fitting nodeR=R1] (nd05) {};
\node[drc,anchor=south,minimum width=6cm,minimum height=0.8cm] (nd06) [above=5pt of nd05.south] {Generic Definition Terms};
\node[drc] (nd07) [above=5pt of nd06.north east,anchor=south east] {Tests \\ (Conversion, Exchange, etc.)};

\draw[drc] let \p1=(nd06.north west), \p2=(nd07.south west), \p3=($(nd07.north west)+(-5pt,5pt)$), \p4=($(nd07.north east)+(0,5pt)$) in (\x1,\y2) -| (\x3,\y3) to node[above left=2pt and -2em]{Plain access} (\x4,\y4) -- ++(0,0.8cm) -| (\x1,\y2);
\node[align=center,rotnt] (nd05titl) [below=2pt of nd05.north,anchor=north] {Generic Definition};

\draw[drc] (-0.5,6) rectangle (7.5,9) [add reference=R2] node[fitting nodeR=R2] (nd08) {};
\node[drc] (nd09) [above right=0pt of nd08.south east, anchor=south east] {Generic List Terms\\Word\ Number\ Variable\ Constant} ;
\draw let \p1=(nd01.center), \p2=(nd09.north) in node[drc] (nd10) at (\x1,\y2) [below=0pt,anchor=north] {Some Terms};
\node[drc] (nd11) [above=0pt of nd10.north,anchor=south] {More Than\\Interesting};
\node[drc] (nd12) [above=0pt of nd09.north,anchor=south] {Generic\\List One};
\node[align=center,rotnt] (nd13) [below=2pt of nd08.north,anchor=north] {Another List};

\draw[arr_edge] (nd01) -- (nd10);
\draw[arr_edge] (nd11) -- (nd12);
\draw[arr_edge] (nd09) -| (nd05);
% wrap in calc $$ for tikzedt
\draw[arr_edge] (nd04) |- ($(nd05.north west)-(10pt,10pt)$) -- ($(nd05.south west)-(10pt,7.5pt)$) -| ($(nd06.south west)+(10pt,0)$);

\end{scope}

\end{tikzpicture}

\end{document}

相关内容