I want to create a tikz list environment, as shown in the figure. So that the vertical space is flexible when x, y, z and w are fractions or drawings.
1 Answers
As Torbjørn T. said in the comments matrices are most likely the way to go (especially when considering that there's drawings to made in the "itemize" environment). But I thought it would be nice to implement this so called itemize in an itemize manner. With that being said, we need a complient \item, also, unfortunately, my skills with LaTeX does not allow me to deal with a pagebreaking system, if someone thinks it's a nice idea, they're welcome to it :)!
The counter can be adjusted in the old fashion way, The label image is made with a node shape which must receive an argument, being that the node name (for drawing the background afterwards. Furthermore, the separation between the label image and label number can be set with label sep and the separation between item entry and label number with numlabel sep. Since in a matrix of nodes when the parser encounters a \path command it does not wrap the contents in a \node{ } and then we can draw as if we were on a tikzpicture, where the origin of the CS is the baseline, that being said we can do something like:
\begin{myitemize}[%
myitem label style={fill=black,yshift=.2mm},
label background={draw, gray, line width=1.2em, shorten <=-2mm}]
\item $\dfrac{1}{2}$\\
\item \draw[scale=0.5] (4,-1.5) node[shift={(-20:-.5)}, centered]{$\theta$} -| coordinate[pos=.5](rect) node[pos=.25, below]{4} node[pos=.75,left](tmp){3} ++(-4,3) -- cycle;
\draw (rect) rectangle node[circle, fill=black, inner sep=0pt, minimum size=1.5pt, centered]{} ++(.2,.2);\\
\item Something else\\
\end{myitemize}
Of course this is not even close to the normal itemize, as is not possible to page break nor do nested itemizes, there are also some problems with alignment of the circle and the label enumeration which can be overcomed with fine adjusments like yshift. Other fine tuning is possible using all TikZ wizardry, such as done with shorten < in the above example.
Finally, the vertical space flexibility is achieved with the \\ at the end of each line, which can be passed an optional argument, being that the vertical space between lines on that row, or the separation between all rows can be set using row sep.
The complete MWE
\documentclass{standalone}
\usepackage{tikz,etoolbox,amsmath}
\usetikzlibrary{matrix,backgrounds}
\newcounter{myitem}
\renewcommand*{\themyitem}{\Alph{myitem}.}
\newcommand{\myitem}{%
\ifnumequal{\value{myitem}}{1}%
{|[myitem label=M-0]| \pgfmatrixnextcell[\myitemizelabelsep] \themyitem\stepcounter{myitem} \pgfmatrixnextcell[\myitemizenumlabelsep]}%
{|[myitem label=M-1]| \pgfmatrixnextcell \themyitem\stepcounter{myitem} \pgfmatrixnextcell}%
}
\newenvironment{myitemize}[1][]{%
\setcounter{myitem}{1}
\let\item\myitem
\begin{tikzpicture}[
myitem label/.style={circle, fill= white, minimum size=.5em, name=##1},
myitem label style/.style={myitem label/.append style={##1}},
label sep/.store in=\myitemizelabelsep, label sep=.5em,
numlabel sep/.store in=\myitemizenumlabelsep, numlabel sep=.2em,
label background/.style={label background style/.style={##1}}, label background={},
row sep=.75em,
#1]
\matrix[matrix of nodes, nodes={inner sep=0pt}, column 1/.style={anchor=south}, column 3/.style={anchor=base west}]\bgroup%
}{%
\\\egroup;
\scoped[on background layer]{
\path[line cap=round, label background style] (M-0.center) -- (M-1.center);};
\end{tikzpicture}
\undef{\item}
}
\begin{document}
\begin{myitemize}[%
myitem label style={fill=black,yshift=.2mm},
label background={draw, gray, line width=1.2em, shorten <=-2mm}]
\item $\dfrac{1}{2}$\\
\item \draw[scale=0.5] (4,-1.5) node[shift={(-20:-.5)}, centered]{$\theta$} -| coordinate[pos=.5](rect) node[pos=.25, below]{4} node[pos=.75,left](tmp){3} ++(-4,3) -- cycle;
\draw (rect) rectangle node[circle, fill=black, inner sep=0pt, minimum size=1.5pt, centered]{} ++(.2,.2);\\
\item Something else\\
\end{myitemize}
\end{document}
When coming to think of this now, perhaps a tabular is more suited...
- 7,787
-
Thanks: but when I compile I get the following error: ! Undefined control sequence. \endmyitemize ->\ \egroup ; \scoped [on background layer]{ \path [line cap=... l.40 \end{myitemize} – casio Jun 06 '17 at 01:39
-
Weird @casio, it works fine for me. Which TeX distro and operating system are you running? – Guilherme Zanotelli Jun 06 '17 at 16:48
-
TeX 3.14159265 (TeX Live 2016/Debian) kpathsea version 6.2.26. System : ubuntu gnome 16.04 – casio Jun 07 '17 at 01:08
-
@casio, are you compiling the MWE in the above answer or did you implement it in your own document? There could be an incompatibility if you're using some custom class... – Guilherme Zanotelli Jun 07 '17 at 15:38
-
-
I'm sorry then. I have no idea what the problem might be. I runned this on Overleaf, my personal computer and my working computer, all compiled without issues... :( – Guilherme Zanotelli Jun 09 '17 at 20:05
-
-
You mean, put the
myitemizeinside anenumerateenvironment? If so, yes, it should work normally, but you'd have to set abaselinefor the tikzpicture in order to get proper alignment, something like:baseline=(current bounding box.north)– Guilherme Zanotelli Jun 10 '17 at 16:33 -
-
I try to put myitemize within the enumerate environment, but I get the following error: missing \ item – casio Jun 11 '17 at 20:45
-
Have you used
\itembefore\begin{myitemize}, e.g.\begin{enumerate} \item \begin{myitemize} ...? – Guilherme Zanotelli Jun 11 '17 at 22:37 -
I used: \begin{enumerate} \item bla bla bla \begin{myitemize} \item x \ \item y \end{myitemize} \end{enumerate} – casio Jun 12 '17 at 14:28
-
Be aware that for the
standaloneclass there's no support for enumerate. You have to change the MWE document class, have you done so? I'm asking because I've tried your example and it worked, though I used aarticleinstead ofstandalone– Guilherme Zanotelli Jun 12 '17 at 15:10 -
I still do not understand, in overleaf it works to wonder. But in my lapto it gives me error. It will be? The installation of texlive the one that will have some error ... – casio Jun 13 '17 at 00:48
-
Without a log file or some more details of the problem it's not easy to help. Doing a fresh and complete install of TL in your system, or updating all packages may help. What can definitely be said is that it's a local issue regarding your system, or TL install... :) – Guilherme Zanotelli Jun 13 '17 at 13:21
-
What will be the best way to install texlive full; Using the console (sudo apt-get install texlive-full) or using synaptic? I use ubuntu gnome 16.04 – casio Jun 13 '17 at 22:11
-
-
Hello, in the end the problem was my distribution of latex ... now, I have another problem, when I use utf8 with the Spanish babel package, and compile, I get error... – casio Sep 23 '17 at 16:29
-
@casio, that's a well known issue: https://tex.stackexchange.com/questions/166772/problem-with-babel-and-tikz-using-draw babel uses
>character as an active one, and TikZ uses it in some of its options, the solution is to deactivate the quoting char before the myitemize env, and re-activate it before when the env. ends\BeforeBeginEnvironment{myitemize}{\deactivatequoting}\AtEndEnvironment{myitemize}{\activatequoting}– Guilherme Zanotelli Sep 24 '17 at 19:29 -
That is, if you are using quoting in your text, if not, a more easy solution is passing to babel
es-noquotinginstead of the usualspanish, that will disable the mechanism babel uses for actively replacing the<>characters. Your call! – Guilherme Zanotelli Sep 24 '17 at 19:31 -
thanks very much, the comand \usepackage[es-noquoting]{babel} solve my problem... i find in https://tex.stackexchange.com/questions/166772/problem-with-babel-and-tikz-using-draw – casio Sep 24 '17 at 21:53




\matrix. Make three columns, place white dots in the first, the label in the second, and X, Y, Z in the third. Then draw the green shapeon background layer(backgroundslibrary), using e.g. thefitlibrary. – Torbjørn T. Jun 04 '17 at 07:16tikzpicturecannot break across pages, like a normal list environment can. Is page breaking a requirement for this? – Torbjørn T. Jun 04 '17 at 14:40