여러 페이지의 여백에 tikz 선 그리기

여러 페이지의 여백에 tikz 선 그리기

이 사이트에서 발견된 코드 부분(기억이 나지 않습니다...)에서 영감을 받아 다음을 수행하여 첫 페이지 위에서부터 시작하는 선을 그릴 수 있었습니다.

\documentclass[a4paper,12pt]{book}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{lipsum}

\begin{document}

\thispagestyle{empty}

\begin{tikzpicture}[remember picture,overlay]
    \node (back names) [shape=rectangle,
    fill=black!80, 
    minimum height=\textheight, 
    minimum width=1cm, 
    anchor=north west] 
    at ([yshift=-(1in+\topmargin+\headheight+\headsep)]current page.north west) {};
\end{tikzpicture}

First line.
Second line.
\lipsum

\end{document}

내가 하고 싶은 것은 직사각형을 긴 텍스트의 끝까지 확장하고(따라서 텍스트를 고려한 매개변수를 사용하여 구축할 '환경' 및/또는 새 명령이 있을 수 있음) 다음을 수행할 수 있도록 하는 것입니다. 시작 또는 끝이 페이지 중간에 있더라도 이 텍스트의 시작 부분에서 정확히 시작하고 끝나는 부분에서 정확히 끝나야 합니다. AND (tiebraker ;))상자를 사용하지 않고.

실제로 저는 mdframed를 사용하여 왼쪽 막대를 왼쪽으로 이동하는 방법을 알고 있습니다. 잘 작동하고 좋습니다.하지만우리는 Framed, mdframed, tcolorbox 등으로 생성된 두 개의 깨지거나 분할 가능한 상자가 중첩될 수 없다는 것을 알고 있습니다(적어도 시도한 경우에는 서로 중첩될 수도 있음). 하지만 그게 제가 하고 싶은 일입니다. tikz로 그리는 선(실제로 큰 규칙)은 컨테이너로 사용되고 그 안에 깨지거나 분리 가능한 다른 상자를 넣을 수 있습니다...

그게 가능합니까? 만든 적 있나요?

편집: 영감은 여기에 있습니다:절대 노드 위치 지정이 포함된 TikZ 전체 페이지.

답변1

이것은 tikzpagenodes, tikzmark 및 Everypage를 사용합니다. 두 번 실행하는 것을 잊지 마십시오.

나는 주로 엉망이 되기 어렵게 만드는 환경을 사용했습니다. OTOH, 중첩된 환경을 다루는 것을 잊어버렸습니다.

\documentclass[a4paper,12pt]{book}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{everypage}

\makeatletter
\newcommand{\checkmarkpage}[4]% #1 = tikzmark label, #2 = less, #3 = equal, #4 = greater
{\@ifundefined{save@pt@#1}{#2}{%
  \edef\markid{\csname save@pt@#1\endcsname}%
  \edef\markpage{\csname save@pg@\markid\endcsname}%
  \ifnum\thepage<\markpage\relax #2%
  \else
    \ifnum\thepage=\markpage\relax #3%
    \else #4%
    \fi
  \fi}%
}
\makeatother

\newcounter{outlineid}
\newcounter{outlinedone}

\newenvironment{outline}{\par\tikzmark{begin\theoutlineid}\ignorespaces}%
  {\par\tikzmark{end\theoutlineid}\stepcounter{outlineid}\ignorespaces}

\newcommand{\drawoutline}{\checkmarkpage{begin\theoutlinedone}{}%
  {\begin{tikzpicture}[remember picture,overlay]
    \path ({pic cs:begin\theoutlinedone}-| current page text area.west)
      ++(0pt,\ht\strutbox) coordinate(A);
    \checkmarkpage{end\theoutlinedone}%
      {\path (current page text area.south west) ++(0pt,-\dp\strutbox)
         coordinate(B);}%
      {\path ({pic cs:end\theoutlinedone}-| current page text area.west)
        ++(0pt,\ht\strutbox) coordinate(B);}%
      {}% this should not happen
    \fill[yellow] ($(A) + (-.333em,0pt)$) rectangle ($(B) + (-1cm,0pt)$);
   \end{tikzpicture}}%
  {\begin{tikzpicture}[remember picture,overlay]
    \coordinate (A) at (current page text area.north west);
    \checkmarkpage{end\theoutlinedone}%
      {\path (current page text area.south west) ++(0pt,-\dp\strutbox)
         coordinate(B);}%
      {\path ({pic cs:end\theoutlinedone}-| current page text area.west)
        ++(0pt,\ht\strutbox) coordinate(B);}%
      {}% this should not happen
    \fill[yellow] ($(A) + (-.333em,0pt)$) rectangle ($(B) + (-1cm,0pt)$);
   \end{tikzpicture}}%
  \checkmarkpage{end\theoutlinedone}{}%
    {\stepcounter{outlinedone}\drawoutline}%
    {}% this should not happen
 }
\AddEverypageHook{\drawoutline}

\begin{document}

\newpage 

\thispagestyle{empty}

\lipsum[1]

Next line begins the rule :

\begin{outline}
\lipsum[2]
\end{outline}

Line above ends the rule.

Two on one page:
\begin{outline}
\lipsum[3]
\end{outline}

One on three pages:
\begin{outline}
\lipsum[4-12]
\end{outline}
That's all, folks.

\end{document}

답변2

답변의 시작입니다. 이제 임의의 선에서 다른 임의의 선으로 규칙을 그릴 수 있습니다.같은 페이지에서. 다음 단계는 다음을 위한 방법을 찾는 것입니다.

1) 마지막 줄 앞 페이지 끝에서 규칙을 중지합니다.

2) 다음 페이지로 이동(현재 페이지+1 ??과 같은 것);

3) 1)-2)를 본문 끝까지 반복합니다...

그리고 아래 코드의 \zsavepos{lineend}는 이 위치가 첫 번째 페이지 이후 1, 2, 3... x 페이지일 수 있다는 사실을 고려하지 않기 때문에 확실히 한두 가지가 더 있습니다! 그리고 그것을 어떻게 알 수 있나요?...

나 한텐 중요해...): Dimtomm(pt 단위의 희미한 값을 mm로 변환)이라는 코드 부분에서 코드 조각(dimwithoutpt)을 사용했지만, 실제로는 Dimexpr의 구문을 이해하지 못합니다(etex-man을 읽었지만... 흠). !). 누군가가 코드를 읽는 방법을 나에게 설명할 수 있다면 좋을 것입니다 :-).

어쩌면 변환과 \beg 및 \portionheight 설정을 수행하는 더 깔끔한 방법이 있을 수도 있지만, 나는 이런 종류의 조작에 전혀 익숙하지 않습니다...

\documentclass[a4paper,12pt]{book}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{layout}
\usepackage{zref-savepos}

\makeatletter
\newcommand\dimwithoutpt[1]{%
    \strip@pt\dimexpr 1\dimexpr#1\relax\relax%
}
\makeatother

\newlength\beg
\newlength\portionheight

\begin{document}
\layout{}

\newpage 

\thispagestyle{empty}

\lipsum[1]

Next line begins the rule :

\zsavepos{linedeb}Begining of my new section.

\setlength{\beg}{dimwithoutpt{\paperheight-\zposy{linedeb}sp}pt}

\lipsum[2]\zsavepos{lineend} 
\setlength{\portionheight}{\dimwithoutpt{\zposy{linedeb}sp-\zposy{lineend}sp}pt}

\begin{tikzpicture}[remember picture,overlay]
    \node (back names) [shape=rectangle, fill=yellow, minimum height=\portionheight, minimum width=1cm, anchor=north west] at ([yshift=-\beg,xshift=1in+\oddsidemargin-1cm]current page.north west) {};
\end{tikzpicture}
Line above ends the rule.

And next : 

\lipsum[3]

\end{document}

관련 정보