Tikz: 다른 노드 오른쪽 여백에 있는 노드는 tcbtheorem과 상호 작용합니다.

Tikz: 다른 노드 오른쪽 여백에 있는 노드는 tcbtheorem과 상호 작용합니다.

현재 @GonzaloMedina의 답변을 사용하려고 합니다.여백 메모를 위한 액자 환경 만들기

다음과 같은 단순화된 코드를 고려해보세요.

\documentclass[oneside]{book}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usepackage{lipsum}


\newcounter{mycaution}
\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]
  \node[inner xsep=0pt,outer sep=0pt] (#1) {};
}

\newcommand{\caution}{
\stepcounter{mycaution}
\tikzmark{\themycaution}%
\begin{tikzpicture}[remember picture,overlay]
\node[draw=red,anchor=west,xshift=\marginparsep,yshift=0pt]   
  (mybox\themycaution)
  at ([yshift=3pt]current page text area.east|-\themycaution) 
  {\parbox{\marginparwidth}{Some text}};
\end{tikzpicture}
}

\begin{document}


\lipsum[1]
Some random text\caution{}
\lipsum[2-5]
\end{document}

이 명령은 \caution내가 예상한 대로 수행됩니다. 호출 전 텍스트 바로 오른쪽 여백에 빨간색 상자가 생성됩니다 \caution.

이제 동일한 작업을 수행하고 싶지만 환경 \caution내부에서 이를 호출한다고 가정합니다 tcbtheorem. 예를 들어:

\documentclass[oneside]{book}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{lipsum}


\newcounter{mycaution}
\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]
  \node[inner xsep=0pt,outer sep=0pt] (#1) {};
}

\newcommand{\caution}{
\stepcounter{mycaution}
\tikzmark{\themycaution}%
\begin{tikzpicture}[remember picture,overlay]
\node[draw=red,anchor=west,xshift=\marginparsep,yshift=0pt]   
  (mybox\themycaution)
  at ([yshift=3pt]current page text area.east|-\themycaution) 
  {\parbox{\marginparwidth}{Some text}};
\end{tikzpicture}
}

\newtcbtheorem{theo}{Theorem}{theorem style=plain}{th}

\begin{document}
\begin{theo}{}{}

Some random text\caution{}
\lipsum[1]
\end{theo}

\lipsum[1]
Some random text\caution{}

\end{document}

그러면 출력은 다음과 같습니다.

출력-tcb

나는 TikZ에 익숙하지 않지만 내가 이해하는 것은 다음과 같습니다.

  • 의 효과는 tikzmark노드가 호출되는 정확한 위치에 노드를 배치하고 이 노드의 좌표를 나중에 사용할 수 있다는 것입니다.
  • 이 좌표를 사용하도록 허용하는 옵션 remember picture, overlay입니다 .tikzpicture

그러나 a tcolorbox(및 a tcbtheorem)는 TikZ를 사용하여 그려지므로 이러한 좌표는 일종의 손실됩니다(문제가 x 좌표에서만 발생한다는 점을 제외하고 y 좌표는 좋은 것 같습니다).

tikzmark생성된 노드에 이름(의 값)을 부여하는 것처럼 보이지만 상자를 그리는 mycaution것과 호출하는 사이에 TikZ가 사용되지 않았다고 가정하면 나중에 이 이름을 실제로 사용하지 않는 것 같습니다 . \tikzmark그러나 이 이름을 사용하여 내 상자가 이 노드의 오른쪽 여백에 있어야 함을 지정하는 방법에 대해서는 전혀 모릅니다...

누구든지 해결책을 제공할 수 있습니까(또는 더 나은: 여기서 실제로 일어나는 일에 대한 설명)?

답변1

문제는 패키지가 정의하는 페이지 노드의 위치를 ​​내부적으로 계산하기 위해 패키지 에서 사용되는 tcolorbox변경 사항 입니다.\textwidthtikzpagenodes

당신은 이것을 사용하여 볼 수 있습니다

\documentclass[oneside]{book}
\usepackage{tikzpagenodes}
\usepackage[most]{tcolorbox}

\newtcbtheorem{theo}{Theorem}{theorem style=plain}{th}

\begin{document}

\the\textwidth
\begin{theo}{}{}
\the\textwidth
\end{theo}

\end{document}

이는 다음을 제공합니다:

여기에 이미지 설명을 입력하세요

따라서 tcolorbox 내에서 current page text area.east노드는 실제로 있어야 하는 위치의 왼쪽에 있습니다.

theo이를 방지하는 한 가지 방법은 패키지의 도움으로 환경 이전에 검색한 올바른 앵커를 사용 etoolbox하고 \caution수정된 앵커를 사용하도록 재정의하는 것입니다.

\documentclass[oneside]{book}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{lipsum}
\usepackage{etoolbox}
\usetikzlibrary{fit}

\newcounter{mycaution}
\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]
  \node[inner xsep=0pt,outer sep=0pt] (#1) {};
}

\newcommand{\caution}{
\stepcounter{mycaution}%
\tikzmark{\themycaution}%
\begin{tikzpicture}[remember picture,overlay]
\node[draw=red,anchor=west,xshift=\marginparsep,yshift=0pt]   
  (mybox\themycaution)
  at ([yshift=3pt]current page text area.east|-\themycaution) 
  {\parbox{\marginparwidth}{Some text}};
\end{tikzpicture}
}

\newtcbtheorem{theo}{Theorem}{theorem style=plain}{th}

\BeforeBeginEnvironment{theo}{%
\tikz[remember picture,overlay]
  \node[fit=(current page text area),line width=0,inner sep=0,name=correct current page text area]{};
\renewcommand{\caution}{
\stepcounter{mycaution}%
\tikzmark{\themycaution}%
\begin{tikzpicture}[remember picture,overlay]
\node[draw=red,anchor=west,xshift=\marginparsep,yshift=0pt]   
  (mybox\themycaution)
  at ([yshift=3pt]correct current page text area.east|-\themycaution) 
  {\parbox{\marginparwidth}{Some text}};
\end{tikzpicture}%
}%
}

\begin{document}

\begin{theo}{}{}
Some random text\caution{}
\lipsum[1]
\end{theo}

\lipsum[1]
Some random text\caution{}

\end{document}

결과:

여기에 이미지 설명을 입력하세요

관련 정보