在垂直时间轴中自定义项目符号

在垂直时间轴中自定义项目符号

基于在垂直时间轴中切换项目符号我想在基于表格的设置中自定义项目符号的外观。我想使用例如\faArrowCircleLeft来自fontawesome包。字形应出现在垂直线上方。但是,由于字形是透明的,我想使用 tikz 在背景中放置一个圆圈。我无法相应地对齐背景,请参见以下示例,其中我使用绿色而不是白色进行演示。

在此处输入图片描述

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{etoolbox}
\usepackage{xtab}
\usepackage{array}
\usepackage{fontawesome5}
\usepackage{graphicx}
\usepackage{tikz}
\definecolor{accentcolor}{RGB}{ 250, 150, 10 }
\definecolor{accentcolortwo}{RGB}{ 50, 150, 10 }

\newbool{time_bullet}
\setbool{time_bullet}{true}

\renewcommand\arraystretch{2.8}

\newcommand{\foo}{\color{accentcolor!80}\vrule width 1pt 
    \makebox[0pt][c]{%
        \ifbool{time_bullet}{%
        \parbox{6pt}{\color{\accentcolor}{\tikz{
    \node[circle,fill=green,text width=0pt, xshift=-0pt, minimum width=0pt,inner sep=0pt, outer sep=0pt] {\faArrowCircleLeft} ;}
    }}\setbool{time_bullet}{false}}
{\setbool{time_bullet}{true}}
}\hskip-0.0pt\hspace{\labelsep}\ifbool{time_bullet}{\global\setbool{time_bullet}{false}}{\global\setbool{time_bullet}{true}}}

\newcolumntype{F}{<{\hskip 0pt} !{\foo} >{\raggedright\arraybackslash}p{3cm}}

\begin{document}

\begin{tabular}{lF}
     1 & Test\\
    2 & Test \\
    3 & Test
\end{tabular}

\end{document}

答案1

我用 LaTeX3 重写了解决方案,它支持 2 以外的步幅值。

在此处输入图片描述

更新

在此处输入图片描述

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{etoolbox}
\usepackage{xtab}
\usepackage{array}
\usepackage{fontawesome5}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{adjustbox}
\usepackage{expl3}

\definecolor{accentcolor}{RGB}{ 250, 150, 10 }
\definecolor{accentcolortwo}{RGB}{ 50, 150, 10 }

\ExplSyntaxOn

\int_new:N \g_bullet_index_int
\dim_new:N \g_bullet_rule_width_dim
% vertical rule width
\dim_gset:Nn \g_bullet_rule_width_dim {1pt}

% bullet stride
\int_new:N \g_bullet_stride_int

% get the width of the arrow
\dim_new:N \g_arrow_width_dim
\hcoffin_set:Nn \l_tmpa_coffin {\faArrowCircleLeft}
\dim_gset:Nn \g_arrow_width_dim {\coffin_wd:N \l_tmpa_coffin}

% the value is used to compensate for bigger circle
% at the bottom
\fp_new:N \g_arrow_width_factor_fp
\fp_gset:Nn \g_arrow_width_factor_fp {0.90}

% compute new arrow width for background circle
\dim_new:N \g__arrow_width_dim
\dim_gset:Nn \g__arrow_width_dim {\fp_use:N\g_arrow_width_factor_fp \g_arrow_width_dim}


% compute lap value
\dim_new:N \g_bullet_lap_dim
\dim_gset:Nn \g_bullet_lap_dim {
  0.5\g_bullet_rule_width_dim + 0.5\g_arrow_width_dim
}

\newcommand*{\resetbullet}{
  \int_gset:Nn \g_bullet_index_int {0}
}

\newcommand*{\setbulletstride}[1]{
  \int_gset:Nn \g_bullet_stride_int {#1}
}

\newcommand{\dobullet}{
  % draw verticle rule
  \color{accentcolor!80}\vrule width \g_bullet_rule_width_dim
  % draw bullet at correct position
  \int_compare:nNnT { \int_mod:nn {\g_bullet_index_int} {\g_bullet_stride_int} } = {0} {
    \color{accentcolor}
    \adjustbox{left=0cm,
      lap=-\g_bullet_lap_dim}{
      \tikz{
        \node[circle, fill=accentcolor!80,
              minimum~width=\g_arrow_width_dim,
              inner~sep=0pt,
              outer~sep=0pt]
              {};
        \node[circle,fill=green,
              % manually tune the width of arrow so that their size fit
              minimum~width=\g__arrow_width_dim,
              inner~sep=0pt, 
              outer~sep=0pt] 
              {};
        \node[inner~sep=0pt,
              outer~sep=0pt]
              {\faArrowCircleLeft};
       }
     }
  }
  \hskip-0.0pt \hspace{\labelsep}
  % increment counter
  \int_gincr:N \g_bullet_index_int
}

\ExplSyntaxOff

\newcolumntype{F}{<{\hskip 0pt} !{\dobullet} >{\raggedright\arraybackslash}p{3cm}}


\begin{document}


\renewcommand\arraystretch{1.2}

% set stride to 2
\setbulletstride{2}
% reset bullet counter before new tabular
\resetbullet

\begin{tabular}{lF}
     1 & Test\\
    2 & Test \\
    3 & Test
\end{tabular}

\vspace{1em}

% set stride to 3
\setbulletstride{3}
% reset bullet counter before new tabular
\resetbullet

\begin{tabular}{lF}
     1 & Test\\
    2 & Test \\
    3 & Test \\
    4 & Test
\end{tabular}

\end{document}

相关内容