체인처럼 작동하도록 사진 찍기

체인처럼 작동하도록 사진 찍기

내가 작성한 코드를 사용하고 있습니다.TikZ를 사용하면 노드를 수평 및 수직으로 분할할 수 있습니까?, 사진으로 만들어 보세요. 이는 가능하지만 연속적으로 배치하면사진s는 문제가 있습니다:사진s, 이름이 지정된 노드는 서로 참조할 수 없더라도 그림 내의 이름이 지정된 노드는 참조할 수 있습니다.

각각의 높이가 같다면사진측정된 후 사진 높이의 절반을 사용하여 사진 위치를 조정할 수 있습니다(선택적 인수 \step(예제 코드 참조)).

최소한의 수동 개입으로 이런 일이 발생하도록 하는 방법에 대해 머리를 감싸는 데 어려움을 겪고 있습니다. 답변은 다음과 같습니다.TiKZ 사진 고정하기어떤 상황에서는 이것이 가능하다고 제안하는 것 같지만 지금까지 이를 사용할 방법을 찾지 못했습니다...

\documentclass{article}

\usepackage{fontspec,tikz}

\usetikzlibrary{calc,positioning,shapes.multipart,fit,backgrounds}

\newcounter{stepnum}
\newcounter{tmpnum}
\newlength{\recwd}

\setlength{\recwd}{2.5in}

%% |=====8><-----| %%

\makeatletter
  \newcommand{\dist}[3]{% #1 cs for result; #2 tikz coord. 1; #3 tikz coord. -- uses calc
  \tikz@scan@one@point\pgfutil@firstofone($(#2)-(#3)$)\relax  
  \pgfmathsetlengthmacro{#1}{veclen(\the\pgf@x,\the\pgf@y)}% <<<--->>>
  }%
\makeatother

\tikzset{pics/hvmpnode/.style n args={3}{% The basic mechanism: #1=L; #2=UR; #3=LR
    code={%
        \node[name=L\thestepnum,rounded corners=1.5pt,fill=cyan!20] {% Left
            \hbox to 1.25em{\hss\textbf{#1}\hss}
        };
        \node[rounded corners,
            rectangle split,
            rectangle split parts=2,
            rectangle split part fill={yellow!80!orange!20,none},
            align=center,
            rounded corners=1.5pt,
            name=R,
            right= 0pt of L\thestepnum.east] {%
                \nodepart{one}\parbox{\recwd}{\centering\strut#2\strut}% UR
                \nodepart{two}\parbox{\recwd}{\parskip1ex\strut#3\strut}
            };% LR
        \draw[thick]  (R.text split east) -- (R.text split west);
        \node[inner sep=0pt,
            draw,
            thick,
            rounded corners=1.5pt,
            name=W\thestepnum,
            anchor=south west,
            fit=(L\thestepnum)(R)] {};% W = enclosing box
        \draw[thick] (W\thestepnum.south west -| R.west) --
            (W\thestepnum.north west -| R.west);% L/R rule
        \begin{scope}[on background layer]
            \fill[cyan!20,rounded corners=1.5pt] (W\thestepnum.north west) rectangle (R.south west);
        \end{scope}
        }%
    }
}

\NewDocumentEnvironment{example}{s O{} m o}{%
    \setcounter{stepnum}{0}%
    \parbox{\textwidth}{%
        \begingroup
            \bfseries
            \itshape
            \Large
            #3
            \par
        \endgroup
        \IfNoValueF{#4}{%
            \par\small\itshape\rightskip=0.5\textwidth plus 3em#4\par
        }%
    }%
    \par
    \medskip
    \begin{tikzpicture}[]
}{%
    \end{tikzpicture}
    \bigskip
}

\NewDocumentCommand{\step}{O{24pt} m +m}{% #1=materials; #2=technique
    \stepcounter{stepnum}%
    \setcounter{tmpnum}{\numexpr\thestepnum-1\relax}
    \ifnum\thestepnum=1
        \path (0,0) pic{hvmpnode={\thestepnum}{#2}{#3}};
    \else
        \path ([yshift=-#1]0,0 |- W\thetmpnum.south west)%% manually setting yshift as optional argument to \step is possible but icky; this aligns but is suspicious 
            pic{hvmpnode={\thestepnum}{#2}{#3}};%% faulty
    \fi
    \dist{\mydist}{W\thestepnum.north}{W\thestepnum.south}\typeout{!!mydist=\mydist!!}
}

%% |=====8><-----| %%

\parindent0pt

\begin{document}

\thispagestyle{empty}

\begin{example}{Foobar}[This is a meaningless bunch of bla bla bla to see if this works in any way, shape, or form.]
\step{1 2 3 4 5 6}{bla bla bla lkfjdlkj}
\step[49.66pt]{z b c d e f 7 8 9}{Much more bla bla bla and this is so much more jejune nonsense and a lot more bubbishy stuff that makes no sense. Much more bla bla bla and this is so much more jejune nonsense and a lot more bubbishy stuff that makes no sense.}
\step[49.66pt]{z b c d e f 7 8 9}{Much more bla bla bla, Much more bla bla bla and this is so much more jejune nonsense and a lot more bubbishy stuff that makes no sense. Much more bla bla bla and this is so much more jejune nonsense an}
\step[19.66pt]{z b c d e f 7 8 9}{Much more bla bla bla}
\end{example}

For the height of each \texttt{pic}, \texttt{\string\typeout} says:

\begin{tabular}{l}
!!mydist=39.33188pt!!\\
!!mydist=99.33188pt!!\\
!!mydist=99.33188pt!!\\
!!mydist=39.33188pt!!
\end{tabular}

\end{document}

그림 체인 ex

답변1

다음은 에서 시작된 아이디어를 사용한 답변입니다.TiKZ 사진 고정하기. 상당히 불가피한 것처럼, 이 답변을 알아내면서 나는 tikzmark 버전에서 수정한 필수 코드의 한 부분에서 버그를 발견했습니다.깃허브(게시 날짜는 2023년 12월입니다. 해당 날짜로부터 몇 달 후에 이 내용을 읽으면 지금쯤 CTAN에 업데이트된 것이 거의 확실합니다.)

키는 그림과 동일한 이름을 가진 그림 주위에 직사각형 노드를 배치하므로 그림이 정의된 후 surround pic와 같은 좌표를 정의하는 데 사용할 수 있습니다 .(<pic name>.south)

그런 다음 키는 pic anchor"앵커"가 지정된 위치에 있도록 그림을 이동하는 코드를 설치합니다. 위치 지정 라이브러리를 사용하면 below=0pt of <previous pic>이 사진의 위치를 ​​지정하는 데 다음과 같은 것을 사용할 수 있음을 의미합니다.

마지막으로, 현재 코드의 기능을 파악하면서 키를 사용하여 하드 코딩 대신 숫자를 굵게 표시하고 중앙에 배치하는 등 이미 존재하는 TikZ-ify 항목에 대해 몇 가지 외관상의 변경을 수행했습니다.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/705474/86}
\usepackage{fontspec,tikz}

\usetikzlibrary{
  calc,
  positioning,
  shapes.multipart,
  fit,
  backgrounds,
  tikzmark
}

\newcounter{stepnum}
\newcounter{tmpnum}
\newlength{\recwd}

\setlength{\recwd}{2.5in}

%% |=====8><-----| %%

\tikzset{
  pics/hvmpnode/.style n args={3}{% The basic mechanism: #1=L; #2=UR; #3=LR
    code={%
      \node[
        name=L\thestepnum,
        rounded corners=1.5pt,
        fill=cyan!20,
        text width=1.25em,
        node font=\bfseries,
        align=center,
        node contents={#1}
      ];
      \node[rounded corners,
        rectangle split,
        rectangle split parts=2,
        rectangle split part fill={yellow!80!orange!20,none},
        align=center,
        rounded corners=1.5pt,
        name=R,
        right= 0pt of L\thestepnum.east] {%
        \nodepart{one}\parbox{\recwd}{\centering\strut#2\strut}% UR
        \nodepart{two}\parbox{\recwd}{\parskip1ex\strut#3\strut}
      };% LR
      \draw[thick]  (R.text split east) -- (R.text split west);
      \node[inner sep=0pt,
        draw,
        thick,
        rounded corners=1.5pt,
        name=W\thestepnum,
        anchor=south west,
        fit=(L\thestepnum)(R)] {};% W = enclosing box
      \draw[thick] (W\thestepnum.south west -| R.west) --
      (W\thestepnum.north west -| R.west);% L/R rule
      \begin{scope}[on background layer]
      \fill[cyan!20,rounded corners=1.5pt] (W\thestepnum.north west) rectangle (R.south west);
      \end{scope}
    }%
  }
}

\NewDocumentEnvironment{example}{s O{} m o}{%
  \setcounter{stepnum}{0}%
  \parbox{\textwidth}{%
    \begingroup
    \bfseries
    \itshape
    \Large
    #3
    \par
    \endgroup
    \IfNoValueF{#4}{%
      \par\small\itshape\rightskip=0.5\textwidth plus 3em#4\par
    }%
  }%
  \par
  \medskip
  \begin{tikzpicture}[]
}{%
  \end{tikzpicture}
  \bigskip
}

\tikzset{
  if number/.code n args={3}{
    \ifnum#1\relax
    \pgfkeysalso{#2}
    \else
    \pgfkeysalso{#3}
    \fi
  }
}

\NewDocumentCommand{\step}{O{24pt} m +m}{% #1=materials; #2=technique
  \stepcounter{stepnum}%
  \setcounter{tmpnum}{\numexpr\thestepnum-1\relax}
  \pic[
    name=hvmp\thestepnum,
    surround pic,
    if number={\thestepnum=1}{}{
      pic anchor, 
      below=0pt of hvmp\thetmpnum,
    }
  ] {hvmpnode={\thestepnum}{#2}{#3}};
}

%% |=====8><-----| %%

\parindent0pt

\begin{document}

\thispagestyle{empty}

\begin{example}{Foobar}[This is a meaningless bunch of bla bla bla to see if this works in any way, shape, or form.]
\step{1 2 3 4 5 6}{bla bla bla lkfjdlkj}
\step[49.66pt]{z b c d e f 7 8 9}{Much more bla bla bla and this is so much more jejune nonsense and a lot more bubbishy stuff that makes no sense. Much more bla bla bla and this is so much more jejune nonsense and a lot more bubbishy stuff that makes no sense.}
\step[49.66pt]{z b c d e f 7 8 9}{Much more bla bla bla, Much more bla bla bla and this is so much more jejune nonsense and a lot more bubbishy stuff that makes no sense. Much more bla bla bla and this is so much more jejune nonsense an}
\step[19.66pt]{z b c d e f 7 8 9}{Much more bla bla bla}
\end{example}

\end{document}

결과(좌표가 확정되도록 몇 번의 컴파일 후):

수직 스택에 위치한 사진을 보여주는 위 코드의 출력

관련 정보