TransWikia.com

Customize bullet points in vertical timeline

TeX - LaTeX Asked by dba on January 6, 2021

Based on Toggle bullet point in vertical timeline I want to customize the appearance of the bullet points in a tabular based setting.
I want to use, e.g. faArrowCircleLeft from fontawesome package. The glyph should appear above the vertical line. However, since the glyph is transparent, I wanted to put a circle in the background using tikz. I am not able to align the background accordingly, see the following example, where I used green color instead of white for the purpose of demonstration.

enter image description here

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}

renewcommandarraystretch{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.0pthspace{labelsep}ifbool{time_bullet}{globalsetbool{time_bullet}{false}}{globalsetbool{time_bullet}{true}}}

newcolumntype{F}{<{hskip 0pt} !{foo} >{raggedrightarraybackslash}p{3cm}}

begin{document}

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

end{document}

One Answer

I rewrite the solution in LaTeX3, which supports stride values other than 2.

enter image description here

Update

enter image description here

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:Ng_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.5g_bullet_rule_width_dim + 0.5g_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} >{raggedrightarraybackslash}p{3cm}}


begin{document}


renewcommandarraystretch{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}

Correct answer by Alan Xiang on January 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP