아래와 같은 큐브가 있습니다. 큐브 아래의 텍스트가 그림과 함께 회전되도록 큐브에 텍스트 속성을 추가하고 싶습니다.
이것이 큐브에 대한 나의 정의이다
\tikzset{
annotated cuboid/.pic={
\tikzset{%
every edge quotes/.append style={midway, auto},
/cuboid/.cd,
#1
}
\draw [\cubeline,every edge/.append style={pic actions,\cubeback, opacity=.5}, pic actions]
(0,0,0) coordinate (o-\cubelabel) -- ++(-\cubescale*\cubex,0,0) coordinate (a-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (b-\cubelabel) edge coordinate [pos=1] (g-\cubelabel) ++(0,0,-\cubescale*\cubez) -- ++(\cubescale*\cubex,0,0) coordinate (c-\cubelabel) -- cycle
(o-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (d-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (e-\cubelabel) edge (g-\cubelabel) -- (c-\cubelabel) -- cycle
(o-\cubelabel) -- (a-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (f-\cubelabel) edge (g-\cubelabel) -- (d-\cubelabel) -- cycle;
},
/cuboid/.search also={/tikz},
/cuboid/.cd,
width/.store in=\cubex,
height/.store in=\cubey,
depth/.store in=\cubez,
units/.store in=\cubeunits,
scale/.store in=\cubescale,
label/.store in=\cubelabel,
line/.store in=\cubeline,
backline/.store in=\cubeback,
width=10,
height=10,
depth=10,
units=cm,
scale=.1,
line=draw,
backline=densely dashed
}
내 전체 코드(MWE):
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{quotes,arrows.meta, decorations.pathreplacing}
\tikzset{
annotated cuboid/.pic={
\tikzset{%
every edge quotes/.append style={midway, auto},
/cuboid/.cd,
#1
}
\draw [\cubeline,every edge/.append style={pic actions, \cubeback, opacity=.5}, pic actions]
(0,0,0) coordinate (o-\cubelabel) -- ++(-\cubescale*\cubex,0,0) coordinate (a-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (b-\cubelabel) edge coordinate [pos=1] (g-\cubelabel) ++(0,0,-\cubescale*\cubez) -- ++(\cubescale*\cubex,0,0) coordinate (c-\cubelabel) -- cycle
(o-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (d-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (e-\cubelabel) edge (g-\cubelabel) -- (c-\cubelabel) -- cycle
(o-\cubelabel) -- (a-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (f-\cubelabel) edge (g-\cubelabel) -- (d-\cubelabel) -- cycle;
;
},
/cuboid/.search also={/tikz},
/cuboid/.cd,
width/.store in=\cubex,
height/.store in=\cubey,
depth/.store in=\cubez,
units/.store in=\cubeunits,
scale/.store in=\cubescale,
label/.store in=\cubelabel,
line/.store in=\cubeline,
backline/.store in=\cubeback,
width=10,
height=10,
depth=10,
units=cm,
scale=.1,
line=draw,
backline=densely dashed,
}
\newcommand{\cuboid}[2]{
\begin{tikzpicture}
\pic [#1] at (0,0) {annotated cuboid={#2}};
\end{tikzpicture}
}
\tikzstyle{cubecontainer}=[outer sep = 0pt, inner sep= 0pt]
\tikzstyle{connectarrow}=[-{Triangle[angle=60:0pt 2]}, line width= 10pt, shorten >=3mm,shorten <=3mm, draw=gray!60]
\begin{document}
\begin{tikzpicture}
\node[cubecontainer] (a) at (0,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}{label=A, width=6, height=20, depth=15, units=mm}};
%\node[cubecontainer] (b) at (2,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}{label=B, width=6, height=20, depth=15, units=mm}};
%\node[cubecontainer] (c) at (5,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}{label=C, width=6, height=20, depth=15, units=mm}};
%%\node[draw,dotted,fit=(a) (b) (c)] {};
\end{tikzpicture}
\end{document}
답변1
다음과 같은 간단한 노드가 \node [below of=a, node distance=1.4cm,rotate=45,xshift=-1cm] (critical) {20x30x20};
비용이 많이 드는 경우에는 Cubecontainer 내부에 레이블을 설정하고 tikzset
회전을 위해 를 사용할 수 있습니다 \rotatebox{45}{#1}
. #1
문서에 정의된 레이블입니다.
\tikzset{cubecontainer/.style={outer sep= 0pt, inner sep= 0pt,label={265:\rotatebox{45}{#1}}}
}%optional with red background ... [fill=red]265 ....
265
0=동쪽부터 360=동쪽까지 시계 반대 방향으로 계산된 위치 지정 각도입니다. (사각형 기준: 0=동쪽, 90=북쪽, 180=서쪽, 270=남쪽,...)
20x20x30
... 그리고 label = ( \node[cubecontainer=20x20x30]
) 로 노드에 레이블을 지정하는 데 사용합니다 .
\node[cubecontainer=20x20x30] (a) at (0,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}{label=A, width=6, height=20, depth=15, units=mm}};
.
편집하다: 2.Verison of cubecontainer
- 다음과 같이 글꼴 크기를 변경합니다.cubecontainer/.style
\tikzset{cubecontainer/.style={outer sep= 0pt, inner sep= 0pt,label={265:\rotatebox{45}{\Huge #1}}} }
- 버전:
- 버전: 글꼴 크기(\Huge)
(첫 번째 버전(왼쪽)과 두 번째 버전(오른쪽) 비교)
MWE:
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{quotes,arrows.meta, decorations.pathreplacing}
\tikzset{
annotated cuboid/.pic={
\tikzset{%
every edge quotes/.append style={midway, auto},
/cuboid/.cd,
#1
}
\draw [\cubeline,every edge/.append style={pic actions, \cubeback, opacity=.5}, pic actions]
(0,0,0) coordinate (o-\cubelabel) -- ++(-\cubescale*\cubex,0,0) coordinate (a-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (b-\cubelabel) edge coordinate [pos=1] (g-\cubelabel) ++(0,0,-\cubescale*\cubez) -- ++(\cubescale*\cubex,0,0) coordinate (c-\cubelabel) -- cycle
(o-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (d-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (e-\cubelabel) edge (g-\cubelabel) -- (c-\cubelabel) -- cycle
(o-\cubelabel) -- (a-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (f-\cubelabel) edge (g-\cubelabel) -- (d-\cubelabel) -- cycle;
;
},
/cuboid/.search also={/tikz},
/cuboid/.cd,
width/.store in=\cubex,
height/.store in=\cubey,
depth/.store in=\cubez,
units/.store in=\cubeunits,
scale/.store in=\cubescale,
label/.store in=\cubelabel,
line/.store in=\cubeline,
backline/.store in=\cubeback,
width=10,
height=10,
depth=10,
units=cm,
scale=.1,
line=draw,
backline=densely dashed,
}
\newcommand{\cuboid}[2]{
\begin{tikzpicture}
\pic [#1] at (0,0) {annotated cuboid={#2}};
\end{tikzpicture}
}
\tikzset{cubecontainer/.style={outer sep= 0pt, inner sep= 0pt,label={[fill=white]265:\rotatebox{45}{#1}}}
}
%\tikzset{cubecontainer/.style={outer sep= 0pt, inner sep= 0pt,label={265:\rotatebox{45}{\Huge #1}}} }
\tikzstyle{connectarrow}=[-{Triangle[angle=60:0pt 2]}, line width= 10pt, shorten >=3mm,shorten <=3mm, draw=gray!60]
\begin{document}
\begin{tikzpicture}
\node[cubecontainer=20x20x30] (a) at (0,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}{label=A, width=6, height=20, depth=15, units=mm}};
%\node [below of=a, node distance=1.4cm,rotate=45,xshift=-1cm] (critical) {20x30x20};
\end{tikzpicture}
\end{document}