
나는 해결하려고 노력하고있다레이블의 텍스트를 회전하지 않고 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}}
추가된 노드는 여전히 "뒤에" 있습니다(따라서 이전 노드를 "커버"하지 않습니다). 그러나 이 접근 방식 은 "정시" 회전을 실행하기 위해 패키지 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}
... 얻기 위해: