
私は解決しようとしているラベルのテキストを回転させずに、Tikz ノードの構成を正しく回転させるにはどうすればよいでしょうか?;そして私は見つけたtikz pgf - 「コマンドの後に追加」と「パスの挿入」に関する問題。
このことから、次のようなアイデアが浮かびました。つまり、スタイルを定義して、単に別のノードを「現在の」ノードの上に配置します。背景は色付きなので、新しいノードが古いノードを覆い隠し、「現在の」ノードと同じ内容ですが、回転します。ここまでは、私が行ったことです。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
% https://tex.stackexchange.com/questions/55722/problem-with-append-after-command-and-insert-path
\makeatletter
\def\mymacro{
\begin{scope}
% { % MUST have this group! or scope!
\setbox\tikz@figbox=\box\pgfutil@voidb@x
\node at (\tikzlastnode) [fill=yellow] {\rotatebox{180}{YY}}; %
% }
\end{scope}
}
\makeatother
\tikzstyle{drc} = [draw, rectangle, line width=1pt, align=center,
append after command={\pgfextra{\mymacro}},
% insert path={\pgfextra{\mymacro}}, % no \tikzlastnode
]
\begin{document}
\begin{tikzpicture}[line width=3mm]
\node[drc] at (0,0) {\ \ A};
\node[drc] at (1,1) {B\ \ };
\end{tikzpicture}
\end{document}
出力は次のようになります。
問題/質問は次のとおりです。
- 追加されたノードは後ろに元のノードなので、その塗りつぶしによって元のノードが隠されることはありません。元のノードの前に配置する方法はありますか?
- 私はテストのために文字を持っているだけです
YY
が、 のテキストを「抽出」したいのです\tikzlastnode
が、 は\tikzlastnode
基本的に最後のノードの名前にすぎず、「オブジェクト参照」ではないようです。いずれにしても、 のテキストを抽出して再利用する方法はありますか\tikzlastnode
?
答え1
最後のノードのボックスを保存する組み込みメソッドはないと思うので、ここでは簡単で簡単な方法を示します (おそらく堅牢ではありません)。
\documentclass[tikz, border=5]{standalone}
\newbox\lastnodebox
\begin{document}
\begin{tikzpicture}[every node/.style={draw,
execute at begin node=\global\setbox\lastnodebox\hbox\bgroup,
execute at end node=\egroup\copy\lastnodebox}]
\foreach \i [count=\y] in {A,...,F}
\node at (0,-\y/2) {\box\lastnodebox \i};
\end{tikzpicture}
\end{document}
編集: OP の例に関して、このアプローチを使用して を介して追加のノードを追加した場合でも、追加されたノードは「後ろ」にあります (したがって、前のノードを「カバー」しません)。ただし、このアプローチは、パッケージの環境append after command={\pgfextra{\mymacro}}
とともにスタイルで直接使用して「時間どおりに」回転を発行できるため、2 番目の回転ノードを「追加」または「オーバーレイ」する必要はありません。したがって、次を使用できます。turn
rotating
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\usepackage{rotating} %tlmgr install rotating
\newbox\lastnodebox
\tikzstyle{drc} = [draw, rectangle, line width=1pt, align=center,]
\tikzstyle{drcr} = [drc,
execute at begin node=\begin{turn}{180}\global\setbox\lastnodebox\hbox\bgroup,
execute at end node=\egroup\copy\lastnodebox\end{turn},
]
\begin{document}
\begin{tikzpicture}[line width=3mm]
\node[drc] at (0,0) {\ \ A\\A\ \ };
\node[drcr] at (1,1) {B\ \ \\\ \ B};
\end{tikzpicture}
\end{document}
... 取得するには: