
두 장의 사진을 그리고 싶은데 두 번째 사진이 첫 번째 사진 아래에 있어야 합니다. 이것이 내가 현재 가지고 있는 것입니다:
두 번째 사진은 어떻게 첫 번째 사진과 동일한 x 좌표를 받을 수 있나요?
암호:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\begin{document}
\tikzset{
pics/vhsplit/.style n args = {3}{
code = {
\node (A) at (0,0) {#1};
\node[anchor=south west] (B) at (A.east) {#2};
\node[anchor=north west] (C) at (A.east) {#3};
\node[inner sep=0pt, outer sep=0pt, draw, rounded corners, fit=(A)(B)(C)] (-box) {};
\draw (B.north west) -- (C.south west)
(B.south west) -- (C.north east);
}
}
}
\begin{tikzpicture}
\pic (a) {vhsplit={a}{2.0}{6.0}};
\pic[below=10mm of a-box.south] (b) {vhsplit={b}{-3.0}{-4.0}};
\end{tikzpicture}
\end{document}
답변1
사진은 노드만큼 똑똑하지 않습니다. 지정된 위치에 배치되는 것은 항상 사진의 원점입니다.
이것이 필요한 전부라면 tabular
노드 내부에 일반 노드를 사용하는 것이 더 쉬울 수 있습니다. 다음은 세 가지 접근 방식입니다.
- 일반 텍스트와 2개의 행과 1개의 열로 구성된 표
→vhsplit
- 두 개의 행과 두 개의 열이 있는 표 형식 하나가 →
#1
에 배치됩니다 .\multirow
vhsplit'
- ㅏ
rectangle split
모양라이브러리 에서shapes.multipart
다시 1과 같은 표 형식을 사용합니다.
→vhsplit''
테이블 형식의 줄은 노드의 경계에 닿아야 하므로 inner sep
s(기본값 .3333em)를 0으로 설정하고 해당 공간을 적절한 위치에 다시 삽입하겠습니다.
왼쪽 부분의 수직 배치는 약간 가변적입니다. 사용 사례에 가장 적합한 것을 선택하십시오(솔루션은 빨간색/녹색/파란색 순서로 표시되며 로 서로 위에 배치됩니다 opacity=.3333
).
암호
\documentclass[tikz,border=2mm]{standalone}
\usepackage{hhline}
\usepackage{multirow}
\usetikzlibrary{positioning}
\tikzset{
vhsplit/.style n args={3}{% text and a tabular
shape=rectangle, draw, rounded corners, inner sep=+0pt,
node contents={%
\setlength{\tabcolsep}{.3333em}%
\hspxsep#1\hspxsep
\begin{tabular}{|l@{\hspxsep}}
\vstysep$#2$\\\hhline{|-}
\vstysep$#3$%
\end{tabular}}},
vhsplit'/.style n args={3}{
shape=rectangle, draw, rounded corners, inner sep=+0pt,
node contents={% multirow in a tabular
\setlength{\tabcolsep}{.3333em}%
\begin{tabular}{l|l@{\hspxsep}}
\multirow{2}{*}{#1} &
\vstysep$#2$\\\hhline{~|-}
& \vstysep$#3$%
\end{tabular}}}}
\usetikzlibrary{shapes.multipart}
\tikzset{
vhsplit''/.style n args={3}{
shape=rectangle split, rectangle split horizontal, rectangle split parts=2,
draw, rounded corners, inner sep=+0pt,
node contents={% two nodeparts and a tabular
\hspxsep#1\hspxsep\null
\nodepart{two}\setlength{\tabcolsep}{.3333em}%
\begin{tabular}{l}
\vstysep$#2$\\\hline
\vstysep$#3$
\end{tabular}}}}
\newcommand*\hspxsep{\hspace{.3333em}}
\newcommand*\vstysep{\rule{0pt}{1.0333em}}
\begin{document}
\begin{tikzpicture}
\node (a) [vhsplit={a}{ 2.0} {6.0}];
\node[below=of a] (b) [vhsplit={b}{-3.0}{-4.0}];
\tikzset{xshift=2cm}
\node (a) (a) [vhsplit'={a} {2.0} {6.0}];
\node[below=of a] (b) [vhsplit'={b}{-3.0}{-4.0}];
\tikzset{xshift=2cm}
\node (a) [vhsplit''={a} {2.0} {6.0}];
\node[below=of a] (b) [vhsplit''={b}{-3.0}{-4.0}];
\end{tikzpicture}
\end{document}
산출
답변2
이 시도:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\begin{document}
\tikzset{
pics/vhsplit/.style n args = {3}{
code = {
\node (A) at (0,0) {#1};
\node[anchor=south west] (B) at (A.east) {#2};
\node[anchor=north west] (C) at (A.east) {#3};
\node[inner sep=0pt, outer sep=0pt, draw, rounded corners, fit=(A)(B)(C)] (-box) {};
\draw (B.north west) -- (C.south west)
(B.south west) -- (C.north east);
}
}
}
\begin{tikzpicture}{scale=3} % <-- changed
\pic (a) {vhsplit={a}{2.0}{6.0}};
\pic[xshift=0cm,yshift=-1cm] (b) {vhsplit={b}{-3.0}{-4.0}};
\end{tikzpicture}
\end{document}
산출: