带垂直线的项目符号列表

带垂直线的项目符号列表

我想以类似于 LinkedIn 的方式添加公司内的不同职位,即用垂直线连接项目符号列表的点。该怎么做?

带垂直线的项目符号列表

编辑:现在完成之后得到一个最小的工作示例一些研究

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\linkedlist}[1]{
  \begin{tikzpicture}[remember picture]%
    \node (#1) [gray,circle,fill,inner sep=1.5pt]{};
  \end{tikzpicture}%
}
\begin{document}

\begin{itemize}
    \item[\linkedlist{a}] test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. 
    \item[\linkedlist{b}] test
    \item[\linkedlist{c}] test
\end{itemize}
\begin{tikzpicture}[remember picture,overlay]
\draw[gray] ($(a)!0.1!(b)$) -- ($(a)!0.9!(b)$);
\draw[gray] ($(b)!0.2!(c)$) -- ($(b)!0.8!(c)$);
\end{tikzpicture}

\end{document}

目前的问题是,我需要在第二个覆盖图片中手动添加线条,并且我使用百分比而不是固定值(例如 2pt)来指定点与线条的开始/结束之间的“间隙”。这会导致间隙的大小根据段落的长度而不同。

答案1

最终解决方案(edit3)

现在,代码应该也适用于列表中的分页符。希望你喜欢它 :) 如果有任何不清楚的地方或需要某些部分的解释,请告诉我!

\documentclass{article}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{refcount}

\newcounter{mylist} % new counter for amount of lists
\newcounter{mycnt}[mylist] % create new item counter
\newcounter{mytmp}[mylist] % tmp counter needed for checking before/after current item

\newcommand{\drawoptionsconn}{gray, shorten <= .5mm, shorten >= .5mm, thick}
\newcommand{\drawoptionsshort}{gray, shorten <= .5mm, shorten >= -1mm, thick}

\newcommand{\myitem}{% Modified `\item` to update counter and save nodes
  \stepcounter{mycnt}%
  \item[\linkedlist{%
    i\alph{mylist}\arabic{mycnt}}]%
  \label{item-\alph{mylist}\arabic{mycnt}}%
  \ifnum\value{mycnt}>1%
    \ifnum\getpagerefnumber{item-\alph{mylist}\arabic{mytmp}}<\getpagerefnumber{item-\alph{mylist}\arabic{mycnt}}%
      \begin{tikzpicture}[remember picture,overlay]%
        \expandafter\draw\expandafter[\drawoptionsshort] (i\alph{mylist}\arabic{mycnt}) --
          ++(0,3mm) --
          (i\alph{mylist}\arabic{mycnt} |- current page text area.north);% draw short line
      \end{tikzpicture}%
    \else%
      \begin{tikzpicture}[remember picture,overlay]%
        \expandafter\draw\expandafter[\drawoptionsconn] (i\alph{mylist}\arabic{mytmp}) -- (i\alph{mylist}\arabic{mycnt});% draw the connecting lines
      \end{tikzpicture}%
    \fi%
  \fi%
  \addtocounter{mytmp}{2}%
  \IfRefUndefinedExpandable{item-\alph{mylist}\arabic{mytmp}}{}{% defined
    \ifnum\getpagerefnumber{item-\alph{mylist}\arabic{mytmp}}>\getpagerefnumber{item-\alph{mylist}\arabic{mycnt}}%
      \begin{tikzpicture}[remember picture,overlay]%
      \expandafter\draw\expandafter[\drawoptionsshort] (i\alph{mylist}\arabic{mycnt}) --
        ++(0,-3mm) --
        (i\alph{mylist}\arabic{mycnt} |- current page text area.south);% draw short line
      \end{tikzpicture}%
    \fi%
  }%
  \addtocounter{mytmp}{-1}%
}

\newcommand{\linkedlist}[1]{
  \raisebox{0pt}[0pt][0pt]{\begin{tikzpicture}[remember picture]%
  \node (#1) [gray,circle,fill,inner sep=1.5pt]{};
  \end{tikzpicture}}%
}

\newenvironment{myitemize}{%
% Create new `myitemize` environment to keep track of the counters
  \stepcounter{mylist}% increment list counter
  \begin{itemize}
}{\end{itemize}%
  }

\begin{document}

\rule[-32\baselineskip]{2pt}{32\baselineskip}
\begin{myitemize}
  \myitem test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph.
  \myitem test
  \myitem test
\end{myitemize}

And a new list:
\begin{myitemize}
\myitem test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph.
\myitem test
\end{myitemize}

\end{document}

新的 MWE 结果


编辑2:\pgfmathsetmacro\result{int(\x-1)}我设法通过使用and\result而不是\pgfmathparse{int(\x-1)}and解决了 @Tom 提到的问题\pgfmathresult。看起来 tikz 用于\pgfmathparse内部计算的代码崩溃了。使用一个名称 ( \result) 可以解决这个问题。此外,我使用了shorten@Ignasi 提供的更简单的语法。

TL;DR:现在thick可以正常工作,其他选项也是如此。

编辑:使代码能够与多个页面上的多个列表配合使用。

我使用列表计数器mylist并遍历每个节点以在新创建的环境的末尾绘制连接线myitemize。这支持多个页面上的多个列表。

原解决方案: 只要您有一个列表,它就可以工作。如果您需要多个列表、分页等,则需要扩展代码。

我使用一个新的计数器来自动命名和保存节点并最终对它们进行迭代。

答案2

您可以使用shorten选项来固定节点边框和线尾之间的特定距离。无需calc

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{calc}

\newcommand{\linkedlist}[1]{
  \begin{tikzpicture}[remember picture]%
    \node (#1) [gray,circle,fill,inner sep=1.5pt]{};
  \end{tikzpicture}%
}
\begin{document}

\begin{itemize}
    \item[\linkedlist{a}] test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. 
    \item[\linkedlist{b}] test
    \item[\linkedlist{c}] test
\end{itemize}
\begin{tikzpicture}[remember picture,overlay]
\draw[gray, shorten >=1mm, shorten <=1mm] (a)-- (b);
\draw[gray, shorten >=1mm, shorten <=1mm] (b)-- (c);
\end{tikzpicture}

\end{document}

在此处输入图片描述

更新

如果itemize用列表替换列表enumerate,则可以声明一个linkedlist完成所有工作并使用常规\items 的新环境。

它仅适用于单级列表,并且不会在页面之间中断。

\documentclass{article}
\usepackage{tikz}

\newcommand{\linkeditem}[1]{
  \begin{tikzpicture}[remember picture]%
  \node (#1) [gray,circle,fill,inner sep=1.5pt]{};
  \end{tikzpicture}%
}

\newenvironment{linkedlist}{%
    \renewcommand{\theenumi}{\protect\linkeditem{\arabic{enumi}}}
    \renewcommand{\labelenumi}{\theenumi}
    \begin{enumerate}
}{ \end{enumerate} \begin{tikzpicture}[remember picture,overlay]
  \ifnum\value{enumi}>1% Only if there are at least 2 bullet points
  \foreach \x [remember=\x as \lastx (initially 1)] 
    in {2,...,\value{enumi}}{% iterate over them
    \draw[gray, shorten >=1mm, shorten <=1mm] (\lastx) -- (\x);}% and draw the connecting lines
  \fi
  \end{tikzpicture}
}

\begin{document}

\begin{linkedlist}
  \item test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph. test with a very long paragraph.
  \item test
  \item test
\end{linkedlist}

\end{document}

相关内容