6

I would like to draw lines to illustrate the lengths used with the package enumitem , so i create this MWE

\documentclass{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\begin{document}
\quad

\vfill \begin{enumerate}[label=\arabic* -, leftmargin=2cm, labelsep= 1.5cm,itemindent=1cm] \item text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text \end{enumerate} \vfill

\begin{tikzpicture}[remember picture, overlay] \coordinate (left) at ($(current page.west)+(1.5,0)$);

\drawred% node[midway ,anchor=north]{\tiny leftmargin}; \drawblue% node[midway,anchor=north]{\tiny itemindent};

\drawred% node[midway,anchor=south]{\tiny labelindent}; \drawblue% node[midway,anchor=south ]{\tiny labelwidth}; \drawred% node[midway,anchor=south]{\tiny labelsep}; \end{tikzpicture}

\end{document}

And we get

enter image description here

But this works only if we place list in the middle of the page, how can i improve this code with tikzmark so lines moves with the list , thanks.

Salim Bou
  • 17,021
  • 2
  • 31
  • 76

2 Answers2

4

Here's another option using the tikzmark ibrary and the tikzpagenodes package; the lengths will automatically adapt according to the enumitem settings used and will display the current value:

enter image description here

The code:

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\usepackage{enumitem}

\def\showlabels#1#2{%
\begin{tikzpicture}[remember picture,overlay]
\draw[red] 
  (current page text area.west|-{pic cs:#2}) --
    node[below,font=\scriptsize] {leftmargin=\the\leftmargin} 
  ++(\leftmargin,0);
\draw[blue] 
  ([xshift=\leftmargin,yshift=-\baselineskip]current page text area.west|-{pic cs:#2}) --
    node[below,font=\scriptsize] {itemindent=\the\itemindent} 
  ([yshift=-\baselineskip]{{pic cs:#1}|-{pic cs:#2}});
\draw[red] 
  ([yshift=3\baselineskip]current page text area.west|-{pic cs:#1}) --
    node[above,font=\scriptsize] {labelindent=\the\labelindent} 
  ++(\labelindent,0);
\draw[blue] 
  ([xshift=\labelindent,yshift=1.5\baselineskip]current page text area.west|-{pic cs:#1}) --
    node[above,font=\scriptsize] {labelwidth=\the\labelwidth}
  ++(\labelwidth,0);
\draw[red] 
  ([xshift=\the\dimexpr\labelindent+\labelwidth\relax,yshift=0.5\baselineskip]current page text area.west|-{pic cs:#1}) --
    node[above,font=\scriptsize] {labelsep=\the\labelsep} 
  ([yshift=0.5\baselineskip]pic cs:#1);
\end{tikzpicture}%
}

\begin{document}

\begin{enumerate}[label=\arabic* -, leftmargin=2cm, labelsep= 1.5cm,itemindent=1cm,align=left]
\item\tikzmark{a}text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text\tikzmark{b}
\showlabels{a}{b} 
\end{enumerate}

\vskip3cm

\begin{enumerate}[label=\arabic* -,labelwidth=60pt,leftmargin=4cm,labelsep=30pt]
\item\tikzmark{c}text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text\tikzmark{d}
\showlabels{c}{d} 
\end{enumerate}

\vskip3cm

\begin{enumerate}
\item\tikzmark{e}text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text\tikzmark{f}
\showlabels{e}{f} 
\end{enumerate}

\end{document}

Simply place a mark immediately after \item using \tikzmark{<name1>} and another one right after the last word of the item using \tikzmark{<name2>} and then use \showlabels{<name1>}{<name2>}. The code needs three runs to stabilize.

Gonzalo Medina
  • 505,128
3

Here, I don't use overlays, but just store the tikz parts in two macros (enummetricsA and \enummetricsZ), which are automatically called when invoking the labelenumerate macro. Because the bottom "leftindent" label would run into the text if it were fixed relative to the top of the environment, I fix it relative to the bottom of the environment.

\documentclass{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\def\enummetricsA{
\begin{tikzpicture}
\coordinate (left) at ($(current page.west)+(1.5,0)$);
\draw[red]($(left)+(0,0.5)$)--($(left)+(1,0.5)$)%
   node[midway,anchor=south]{\tiny labelindent};
\draw[blue]($(left)+(1,1)$)--($(left)+(1.5,1)$)%
   node[midway,anchor=south ]{\tiny labelwidth};
\draw[red]($(left)+(1.5,0.5)$)--($(left)+(3,0.5)$)%
   node[midway,anchor=south]{\tiny labelsep};
\end{tikzpicture}}
\def\enummetricsZ{
\begin{tikzpicture}[remember picture]
\coordinate (left) at ($(current page.west)+(1.5,0)$);
\draw[red]($(left)+(0,-1)$)--($(left)+(2,-1)$)%
   node[midway ,anchor=north]{\tiny leftmargin};
\draw[blue]($(left)+(3,-1.3)$)--($(left)+(2,-1.3)$)%
   node[midway,anchor=north]{\tiny itemindent};
\end{tikzpicture}}

\newenvironment{labelenumerate}
{\noindent\kern-2.1ex\smash{\raisebox{-1.1\baselineskip}{\enummetricsA}}\begin{enumerate}}
{\end{enumerate}\noindent\kern-0.9ex\smash{\raisebox{-.0\baselineskip}{\enummetricsZ}}}

\begin{document}
\quad

\bigskip
\begin{enumerate}[label=\arabic* -, leftmargin=2cm, labelsep= 1.5cm,itemindent=1cm]
\item text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
\end{enumerate}%

\begin{enumerate}[label=\arabic* -, leftmargin=2cm, labelsep= 1.5cm,itemindent=1cm]
\item text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
\end{enumerate}%

\begin{labelenumerate}[label=\arabic* -, leftmargin=2cm, labelsep= 1.5cm,itemindent=1cm]
\item text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
\end{labelenumerate}%

\begin{enumerate}[label=\arabic* -, leftmargin=2cm, labelsep= 1.5cm,itemindent=1cm]
\item text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
\end{enumerate}%

\begin{labelenumerate}[label=\arabic* -, leftmargin=2cm, labelsep= 1.5cm,itemindent=1cm]
\item text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
\end{labelenumerate}%

\end{document}

enter image description here