我试图绘制一个项目列表,而不是 unline itemize
,其中所有点都由垂直线连接。换句话说,我的目标是一种垂直时间轴,但没有日期。事实上,我已经从 TikZ 答案中窃取灵感,我的意思是从中汲取灵感如何创建垂直时间线?,但我有两个主要问题:
- 列表项超出了页面限制,但它们应该保留在页面内,就像实际的
itemize
- 列表项目前不接受
\par
,\\
虽然我需要支持这些
以下是我目前所掌握的信息:
\documentclass{article}
\usepackage{environ,tikz}
\usetikzlibrary{calc,matrix,backgrounds}
\makeatletter
\let\matamp=&
\catcode`\&=13
\def&{%
\iftikz@is@matrix%
\pgfmatrixnextcell%
\else%
\matamp%
\fi%
}
\makeatother
\newcounter{lines}
\def\endlr{\stepcounter{lines}\\}
\newcounter{vtml}
\setcounter{vtml}{0}
\tikzset{
description/.style={column 2/.append style={#1}},
timeline color/.store in=\vtmlcolor,
timeline color=red!80!black,
timeline color st/.style={fill=orange,draw=green},
line offset/.store in=\lineoffset,
line offset=4pt,
}
\NewEnviron{vtimeline}[1][]{%
\setcounter{lines}{1}%
\stepcounter{vtml}%
\begin{tikzpicture}[%column 1/.style={anchor=east},
column 1/.style={anchor=west},
text depth=0pt,text height=1ex,
row sep=1ex,
column sep=1em,
#1
]
\matrix(vtimeline\thevtml)[matrix of nodes]{\BODY};
\pgfmathtruncatemacro\endmtx{\thelines-1}
\foreach \x in {1,...,\endmtx}{
\node[circle,timeline color st, inner sep=0pt, minimum size=10pt, line width=.75mm]
(vtimeline\thevtml-c-\x) at
($(vtimeline\thevtml-\x-1.west) + (-1ex, 0)$){};
}
\begin{scope}[on background layer]
\draw[blue, line width=1mm] (vtimeline\thevtml-c-1.center) -- (vtimeline\thevtml-c-\endmtx.center);
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{vtimeline}%[row sep=4ex]
This is a very long sentence, hopefully it will generate a new line, otherwise I will have to keep writing nonsense on and on and on and on\endlr
Xerox Palo Alto Research Centre envisage the `Dynabook'\endlr
Busicom 'Handy-LE' Calculator\endlr
First mobile handset invented by Martin Cooper\endlr
Parker Bros. Merlin Computer Toy\endlr
Osborne 1 Portable Computer\endlr
Grid Compass 1100 Clamshell Laptop\endlr
TRS-80 Model 100 Portable PC\endlr
Psion Organiser Handheld Computer\endlr
Psion Series 3 Minicomputer\endlr
\end{vtimeline}
\end{document}
你对下一步有什么建议吗?提前谢谢!
PS 我知道我选择的颜色很难看,事实上它们是临时的,只是为了测试目的。此外,我真的很想能够使用 TikZ 来实现这一点,因为这是更复杂的事情的第一步,如果没有 TikZ,我不知道该怎么做。
答案1
我不知道这个想法是否足够。问题是逗号是列表分隔符;您不能在项目中直接使用它,但可以使用花括号,即{,}
(参见示例)。
注意,项目之间的距离是相同的。您可以通过node distance
值来控制它。此外,您还可以使用\\
在项目内部换行。
代码
\documentclass[11pt, margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{math, arrows.meta}
\usetikzlibrary{positioning}
\begin{document}
\newcommand{\linedlist}[1]{\noindent%
\begin{tikzpicture}[every node/.style={node distance = 6ex and 1.5ex}]
\node[anchor=west] at (0, 0) (S-0) {};
\tikzmath{ integer \nbPoints; }
\foreach \s [count=\i from 1, evaluate=\i as \j using {int(\i-1)}]
in {#1}{%
\node[below=of S-\j.south west, anchor=west, align=left] (S-\i) {\s};
\node[left=of S-\i,
draw=red, circle, shade, ball color=red,
outer sep=0, inner sep=.65ex] (N-\i) {};
\pgfextra{\xdef\nbPoints{\i}}
}
\foreach \i [parse=true, evaluate=\i as \j using {int(\i+1)}]
in {1, ..., \nbPoints -1}{%
\draw[thick] (N-\i) -- (N-\j);
}
\end{tikzpicture}
}
\linedlist{
If you can't explain it to a six year old{,}
you don't \\
understand it yourself.,
The important thing is to not stop questioning.,
Look deep into nature{,} and then you will \\
understand everything better.,
A happy man is too satisfied with the present \\
to dwell too much on the future.
}
\end{document}