このサイトで見つかったコードの一部(覚えていないのですが...)に触発されて、最初のページの上から線を引くには次のようにします。
\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}
私がやりたいのは、長方形を長いテキストの最後まで拡張することです (そのため、テキストを考慮したパラメータを持つ新しいコマンドや構築する「環境」がある可能性があります)。また、開始または終了がページの中央にある場合でも、このテキストの先頭から開始して終了する場所で正確に終了できるようにし、さらに (タイブレーカー ;))箱を使わずに。
実際、私はこれを、例えばmdframedを使って左のバーを左にシフトする方法を知っています...うまく機能し、素晴らしいですしかしframed、mdframed、tcolorbox などで作成された 2 つの壊れやすい/分割可能なボックスはネストできないことはわかっています (少なくとも私が試したケースでは、1 つをもう 1 つとネストすることさえできません)。しかし、それが私がやりたいことです。tikz で描画している線 (実際には大きなルール) をコンテナーとして使用し、その中に他の壊れやすい/分割可能なボックスを配置できるようにします...
それは可能ですか?これまでに作られたことがありますか?
編集: インスピレーションはここにあります:絶対ノード配置による TikZ フルページ。
答え1
これは tikzpagenodes、tikzmark、everypage を使用します。 2 回実行することを忘れないでください。
環境を使用したのは、主に失敗しにくくするためです。一方で、ネストされた環境に対処することを忘れていました。
\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 ページ後になる可能性があるという事実が考慮されていないため、もう 1 つまたは 2 つあります。それをどうやって知るのでしょうか?...
重要なこと(私にとっては...): 私は、dimtomm (pt の dim を 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}