当我试图让 itemize 环境的层次结构更加“可见”时,我发现这个很好回答来自 @schtandard 对原始问题的回复使 itemize 看起来像 dirtree:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{tikz}
\makeatletter
\newlist{treelist}{itemize}{5}
\setlist[treelist]{label=\treelist@label}
\tikzset{treelist line/.style={thick, line cap=round, rounded corners}}
\def\treelist@label{%
\begin{tikzpicture}[remember picture, baseline={([yshift=-.6ex] treelist-bullet-\the\[email protected])}]
\draw [treelist line] (0, 0) -- node (treelist-bullet-\the\enit@depth) {} ++(.5em, 0);
\end{tikzpicture}%
\ifnum\enit@depth>1
\tikz[remember picture, overlay] \draw [treelist line] (treelist-bullet-\the\numexpr\enit@depth-1\relax.center) |- (treelist-bullet-\the\[email protected]);%
\fi
}
\makeatother
\begin{document}
\begin{treelist}
\item
Gas ideal (partículas idénticas que no interactúan, i.e.~la energía no tiene términos cruzados).
\begin{treelist}
\item
Fermiones.
\begin{treelist}
\item
Límite de gas no degenerado.
Corresponde a temperaturas muy altas y densidades muy bajas, el resultado es el gas ideal clásico.
\item
Límite de gas degenerado.
Es lo opuesto, temperaturas bajas y densidades altas.
Aparece Pauli con su principio de exclusión.
\begin{treelist}
\item
Enanas blancas.
\end{treelist}
\end{treelist}
\item
Bosones.
\begin{treelist}
\item
Límite de gas no degenerado.
Corresponde a temperaturas muy altas y densidades muy bajas, el resultado es el gas ideal clásico.
\begin{treelist}
\item
Gas de fotones.
\item
Gas de fonones.
\end{treelist}
\item
Límite de gas degenerado.
Básicamente es un condensado de Bose-Einstein.
\begin{treelist}
\item
Superfluidos.
\item
Superconductores.
\end{treelist}
\end{treelist}
\end{treelist}
\item
Otros temas que no sean gas ideal. No vimos nada, creo.
\end{treelist}
\end{document}
不幸的是,我有很多项目要展示,当分页符出现时,连接线就会丢失。我找到了另一个邮政来自@Schrödinger 的猫,展示了如何获取跨越多页注释之间的箭头:
\documentclass[10pt,oneside]{scrbook}
\usepackage{lipsum}
\usepackage[left=32.5mm, right=22.5mm, top=25mm, bottom=20mm, marginparsep=3mm]{geometry}
\usepackage{tikzpagenodes}
\usepackage{eso-pic}
\usetikzlibrary{tikzmark}
\usepackage{marginnote}
\renewcommand*{\marginfont}{\footnotesize\itshape}
\makeatletter
\newcommand\PageOfTikzmark[1]{%
\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname}
\makeatother
\newcommand{\ConnectTikZmarknodes}[3][]{\AddToShipoutPictureFG{%
\begin{tikzpicture}[remember picture, overlay, shorten >=1.5mm,
shorten <=1.5mm,#1]
\iftikzmark{#2}{\edef\pageA{\PageOfTikzmark{#2}}}{\edef\pageA{-1}}%
\iftikzmark{#3}{\edef\pageB{\PageOfTikzmark{#3}}}{\edef\pageB{-1}}%
\iftikzmarkoncurrentpage{#2}
\edef\myflag{1}%
\else
\edef\myflag{0}%
\fi
\iftikzmarkoncurrentpage{#3}
\edef\myflag{\the\numexpr\myflag+2}%
\fi
\ifcase\myflag
\or
\draw[-] ([xshift=10pt]#2.south west)
to ([xshift=10pt]#2.south west|-current page text area.south);
\or
\draw[->] ([xshift=10pt]#3.north west|-current page text area.north)
to ([xshift=10pt]#3.north west);
\or
\draw[->] ([xshift=10pt]#2.south west)
to ([xshift=10pt]#3.north west);
\fi
\ifnum\value{page}>\pageA
\ifnum\value{page}<\pageB
\draw ([xshift=20pt]current page text area.north east) to
([xshift=20pt]current page text area.south east);
\fi
\fi
\end{tikzpicture}}}
\begin{document}
\marginnote{\tikzmarknode{a}{Thermoplast}}
\lipsum[1]
\marginnote{\tikzmarknode{b}{teilkristallin}}
\ConnectTikZmarknodes{a}{b}
\lipsum[1]
\marginnote{\tikzmarknode{c}{aliphatisch}}
\ConnectTikZmarknodes{b}{c}
\lipsum[1-7] % works fine
\marginnote{\tikzmarknode{d}{aliphatisch}}
\ConnectTikZmarknodes{c}{d}
\ConnectTikZmarknodes{d}{e}
\lipsum[1-23]
\marginnote{\tikzmarknode{e}{unproblematisch}}
\end{document}
所以我的问题是:是否可以将这两种解决方案结合起来?如何建立跨越分页符的树形列表的连接?
有人能帮忙吗?提前感谢您的努力。
编辑: @Schrödinger 的猫提供了一个很好的解决方案。但我忘了指出,跨分页符可能有多个连接。从下图可以看出,应该有一个从“费米子”向下到“非简并费米气体”和“准简并费米气体”的连接。
对应的代码是:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\makeatletter
\newcommand\PageOfTikzmark[1]{%
\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname}
\newlist{treelist}{itemize}{5}
\setlist[treelist]{label=\treelist@label}
\tikzset{treelist line/.style={thick, line cap=round, rounded corners},
treelist cutoff/.initial=3\baselineskip}
\def\treelist@label{%
\tikzmarknode{treelist-\the\enit@depth}{\textbullet}%
\ifnum\enit@depth>1\relax
\iftikzmark{treelist-\the\numexpr\enit@depth-1}{%
\begin{tikzpicture}[remember picture, overlay]
\draw let \p1=(treelist-\the\enit@depth),
\p2=(treelist-\the\numexpr\enit@depth-1)
in
\ifdim\y2>\y1
(treelist-\the\enit@depth) -|
(treelist-\the\numexpr\enit@depth-1\relax);
\else
(treelist-\the\enit@depth) -|
(treelist-\the\numexpr\enit@depth-1\relax|-current page text area.north);
\fi;
\draw let \p1=($(treelist-\the\enit@depth)-(current page text area.south)$)
in
\ifdim\y1<\pgfkeysvalueof{/tikz/treelist cutoff}
(treelist-\the\enit@depth) -|
(treelist-\the\numexpr\enit@depth-1\relax|-current page text area.south);
\fi;
\end{tikzpicture}%
}{%
}%
\fi
}
\makeatother
\begin{document}
\begin{treelist}
\item Ideal gas of noninteracting particles.
\begin{treelist}
\item
Fermions.
\begin{treelist}
\item Non--degenerate Fermi gas. The Pauli principle plays no major
role.
\item Quasi--degenerate Fermi gas. The Pauli principle is important
and dictates the occupation number.
\begin{treelist}
\item
Whatever.
\end{treelist}
\end{treelist}
\item
Bosons.
\begin{treelist}
\item Non--degenerate Bose gas.
\begin{treelist}
\item Photons.
\item Phonons.
\end{treelist}
\item Quasi--degenerate Bose gas.
Bose--Einstein condensation.
\begin{treelist}
\item
Superfluids.
\item
Superconductors.
\end{treelist}
\end{treelist}
\end{treelist}
\item Ti\emph{k}Zlings
\begin{treelist}
\item Anteater
\item Bear
\item Bee
\item Cat
\item Coati
\item Hippo
\item Koala
\item Marmot
\item Mole
\item Mouse
\item Panda
\item Penguin
\item Pig
\item Rhino
\item Sloth
\item Squirrel
\item Snowman
\end{treelist}
\item Ideal gas of noninteracting particles.
\begin{treelist}
\item
Fermions.
\begin{treelist}
\item Non--degenerate Fermi gas. The Pauli principle plays no major
role.
\item Quasi--degenerate Fermi gas. The Pauli principle is important
and dictates the occupation number.
\begin{treelist}
\item
Whatever.
\end{treelist}
\end{treelist}
\item
Bosons.
\begin{treelist}
\item Non--degenerate Bose gas.
\begin{treelist}
\item Photons.
\item Phonons.
\end{treelist}
\item Quasi--degenerate Bose gas.
Bose--Einstein condensation.
\begin{treelist}
\item
Superfluids.
\item
Superconductors.
\end{treelist}
\end{treelist}
\end{treelist}
\end{treelist}
\end{document}
据我所知,每个列表标签周围都放置了一个节点。通过检查是否存在深度值较低的节点,可以建立连接。根据节点的 y 坐标,绘制一条线到深度值较低的节点或“当前页面文本区域.南”/“当前页面文本区域.北”节点。但这似乎会导致如上所示的嵌套树列表出现一些问题。
答案1
这是一种临时方法。困难的是要找出某个项目在下一页是否有子项。此处通过计算到文本区域下端的距离来完成此检查。检查可能并不总是准确的。您可以使用以下方法更改截止值
\tikzset{treelist cutoff=<dimension>}
如果发生这种情况,请本地
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\makeatletter
\newcommand\PageOfTikzmark[1]{%
\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname}
\newlist{treelist}{itemize}{5}
\setlist[treelist]{label=\treelist@label}
\tikzset{treelist line/.style={thick, line cap=round, rounded corners},
treelist cutoff/.initial=1.5\baselineskip}
\def\treelist@label{%
\tikzmarknode{treelist-\the\enit@depth}{\textbullet}%
\ifnum\enit@depth>1\relax
\iftikzmark{treelist-\the\numexpr\enit@depth-1}{%
\begin{tikzpicture}[remember picture, overlay]
\draw let \p1=(treelist-\the\enit@depth),
\p2=(treelist-\the\numexpr\enit@depth-1)
in
\ifdim\y2>\y1
(treelist-\the\enit@depth) -|
(treelist-\the\numexpr\enit@depth-1\relax);
\else
(treelist-\the\enit@depth) -|
(treelist-\the\numexpr\enit@depth-1\relax|-current page text area.north);
\fi;
\draw let \p1=($(treelist-\the\enit@depth)-(current page text area.south)$)
in
\ifdim\y1<\pgfkeysvalueof{/tikz/treelist cutoff}
(treelist-\the\enit@depth) -|
(treelist-\the\numexpr\enit@depth-1\relax|-current page text area.south);
\fi;
\end{tikzpicture}%
}{%
}%
\fi
}
\makeatother
\begin{document}
\begin{treelist}
\item Ideal gas of noninteracting particles.
\begin{treelist}
\item
Fermions.
\begin{treelist}
\item Non--degenerate Fermi gas. The Pauli principle plays no major
role.
\item Quasi--degenerate Fermi gas. The Pauli principle is important
and dictates the occupation number.
\begin{treelist}
\item
Whatever.
\end{treelist}
\end{treelist}
\item
Bosons.
\begin{treelist}
\item Non--degenerate Bose gas.
\begin{treelist}
\item Photons.
\item Phonons.
\end{treelist}
\item Quasi--degenerate Bose gas.
Bose--Einstein condensation.
\begin{treelist}
\item
Superfluids.
\item
Superconductors.
\end{treelist}
\end{treelist}
\end{treelist}
\item Ti\emph{k}Zlings
\begin{treelist}
\item Anteater
\item Bear
\item Bee
\item Cat
\item Coati
\item Hippo
\item Koala
\item Marmot
\item Mole
\item Mouse
\item Panda
\item Penguin
\item Pig
\item Rhino
\item Sloth
\item Squirrel
\item Snowman
\end{treelist}
\item Ti\emph{k}Zlings
\begin{treelist}
\item Anteater
\item Bear
\item Bee
\item Cat
\item Coati
\item Hippo
\item Koala
\item Marmot
\item Mole
\item Mouse
\item Panda
\item Penguin
\item Pig
\item Rhino
\item Sloth
\item Squirrel
\item Snowman
\end{treelist}
\end{treelist}
\end{document}
其他东西就更容易定制了。很容易把项目符号改成别的东西。