12

I am trying to create a new enumerate list with custom shape as its label. I want to have:

Goal 1. the label aligned at the center of the text. (top figure below)

Goal 2. vertical line after the circle spans the height of the text. (bottom figure below)

fancylist demo

In the MWE below, I have achieved the basic design using enumitem package. However, I am struggling to get the correct alignment for the label.

\documentclass{article}
\usepackage{enumitem}
\usepackage{tikz}

\newcounter{fancycount}
\let\realitem\item
\newcommand\fakeitem[1][\relax]{
    \refstepcounter{fancycount}
    \realitem[\tikz{\node[circle, draw=green, minimum width=1cm, fill=green, anchor=west](a){\LARGE\arabic{fancycount}}; \draw[very thick, green] ([xshift=1cm]a.north) -- ([xshift=1cm]a.south)}#1]
}


\newlist{fancylist}{enumerate}{1}

\setlist[fancylist]{
    label=\arabic*.,   % label format
    leftmargin=*,      % indent labels
    before=\let\item\fakeitem,
}

\begin{document}

\begin{fancylist}
    \item This is point 1.
    \item This is point 2.
    \item This is a big point which goes on for lines....\\
    too many lines \\
    and some more lines \\
    ends finally. 
\end{fancylist}

\end{document} 

The MWE generates the following output:

fancylist now

Is there a way to achieve Goal 1 and Goal 2 (or at least one of them)? Thanks for your help.

1
  • Updated my previous answer with a completely new solution using tcolorbox.
    – Masroor
    Aug 10, 2017 at 9:13

1 Answer 1

11

NEW SOLUTION

This is a completely new solution using tcolorbox.

This solution fulfills both of your goals.

You can adjust the dimensions and lengths to suit your taste.


\documentclass{article}

\RequirePackage[most]{tcolorbox}

\usepackage{lipsum}

\newcounter{fancycount}

\newenvironment{fancyenumerate}{%
  \setcounter{fancycount}{0}
  \begin{tcbitemize}[raster columns=1,    
    nofloat,
    enhanced,
    raster left skip=15.0mm,
    sharp corners=all,
    colback=white,
    colframe=green,
    toprule=0.0mm,
    bottomrule=0.0mm,
    leftrule=1.0mm,
    rightrule=0.0mm,
    boxsep=0.005\textwidth,
    valign=center,
    overlay={\coordinate (X) at ([xshift=-7.50mm]frame.west);
      \node[draw,circle,minimum width=10.0mm,inner sep=0pt,color=green,fill=green,text=black] at (X) {\refstepcounter{fancycount}\LARGE\arabic{fancycount}};}]}{\end{tcbitemize}}

\begin{document}

\section{First List}

\begin{fancyenumerate}
  \tcbitem Short.  

  \tcbitem Middle middle middle middle middle middle middle
  middle middle middle middle.  

  \tcbitem \textbf{Long} \lipsum[1]
\end{fancyenumerate}

\section{Another List, Check that the Counter is Being Reset Properly}

\begin{fancyenumerate}
  \tcbitem One.

  \tcbitem Two\\ii,\\ II,\\ and 2.

  \tcbitem Three.

  \tcbitem Four.
\end{fancyenumerate}

\end{document}

enter image description here

ORIGINAL SOLUTION

I am using the \adjustbox to vertically center the item labels. I don't like the idea that longer text items will have to be put inside a minipage. Let me see whether I can automate this.


\documentclass{article}
\usepackage{enumitem}
\usepackage{tikz}

\newcounter{fancycount}
\let\realitem\item
\newcommand\fakeitem[1][\relax]{
    \refstepcounter{fancycount}
    \realitem[\adjustbox{valign=c}{\tikz{\node[circle, draw=green, minimum width=1cm, fill=green, anchor=west](a){\LARGE\arabic{fancycount}}; \draw[very thick, green] ([xshift=1cm]a.north) -- ([xshift=1cm]a.south)}#1}]
}


\newlist{fancylist}{enumerate}{1}

\setlist[fancylist]{
    label=\arabic*.,   % label format
    leftmargin=*,      % indent labels
    before=\let\item\fakeitem,
}

\usepackage{adjustbox}

\begin{document}

\begin{fancylist}
    \item This is point 1.

    \item This is point 2.
    \item \begin{minipage}[c]{0.8\linewidth}
        This is a big point which goes\\ on for lines....  too many
        lines and\\ some more lines ends finally.
      \end{minipage}

\end{fancylist}

\end{document}

enter image description here

2
  • Just adding few points: 1. tcolorbox adds a background color to the box (white here). If transparency is needed then option opacityfill=0 can be added. This will make frame transparent as well. So we may remove frame parameters from the options list. Vertical line can be drawn in overlay. 2. tcolorbox also sets color for body text which can be changed by adding coltext=<color> to the options if needed.
    – Adarsh
    Aug 11, 2017 at 6:31
  • @Adarsh Thanks a lot. I first encountered tcolorbox in my life only two days ago. So, my knowledge of this wonderful tool is very minimal. And the manual is huge, almost 500 pages. Definitely your comments will further enrich my humble solution.
    – Masroor
    Aug 11, 2017 at 8:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .