0

I want to enumerate and itemize inside a rectangle shape. Example figure as follows:

enter image description here

Reference: The Linux Programming Interface, page 454

I want to place this node in \tikzpicture. I can draw simple rectange filling inside with text but I was not able to create enumerate items inside of it.

1
  • Please provide some code that shows what you have got so far. You will need to place the list inside a \parbox or minipage if you want to use it inside a node. Also, you may want to have a look at the enumitem package that provides a lof of options to set the spacing of such lists. Aug 4 at 11:59

3 Answers 3

3

You need to place itemize or enumerate environments in some kind of box (\parbox, minipage etc.), if you want to use them inside a node. Since you also mentioned spacing, I would suggest you to look at the enumitem package that provides some useful options to adjust spacing of such lists. You could do something like this:

\documentclass[border=10pt]{standalone}  
\usepackage{tikz}  
\usepackage{enumitem}  

\begin{document}  
    \begin{tikzpicture}  
        \node[draw] at (0,0) {\parbox{7cm}{%}
            \begin{enumerate}[nosep, left=0pt]
                \item Pending \texttt{SIGINT} and \texttt{SIGQUIT} unblocked 
                \item Kernel invokes hanlder for \texttt{SIGINT} 
                \item \texttt{SIGINT} handler makes a system call
                \item Kernal invokes handler for \texttt{SIGQUIT} 
            \end{enumerate}%
        }};
    \end{tikzpicture}
\end{document}

enter image description here


Edit

Two things to add:

  1. If you don't want indentation for the items, use the wide option.

  2. If you want to make the box as wide as \columnwidth, you can set the with of the inner \parbox to \columnwidth (which is then the width inside the node) minus twice the inner xsep (the padding inside the node). You will still get a warning about an overfull hbox, because the border of the node exactly sits on the margins of the text in the column. The border is 0.4 pt wide and overlaps to the left and the right with half of its width, which renders the width of the box 0.4 pt too wide.

So, in the end you would get (I added a \hrule to show the length of \columnwidth):

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

\begin{document}  

    \hrule\bigskip % show \columnwidth

    \noindent
    \begin{tikzpicture}
        \node[draw] at (0,0) {%
        \parbox{\dimexpr\columnwidth-(\pgfkeysvalueof{/pgf/inner xsep})*2\relax}{%
            \begin{enumerate}[nosep, wide]
                \item Pending \texttt{SIGINT} and \texttt{SIGQUIT} unblocked and a long line, a unbelievably long line even
                \item Kernel invokes hanlder for \texttt{SIGINT} 
                \item \texttt{SIGINT} handler makes a system call
                \item Kernal invokes handler for \texttt{SIGQUIT} 
            \end{enumerate}%
        }};
    \end{tikzpicture}

\end{document}

enter image description here

However, if you only want draw a box around an enumeration, it might be better just to use an \fbox (see John Kormylo's answer).

7
  • If a item has a long string that has two lines is it also possbile to start the second line without indent
    – alper
    Aug 5 at 10:04
  • can \parbox set to slightly smaller to column-width by default?
    – alper
    Aug 5 at 11:23
  • \columnwidth seems little bit exceeds the column in double column
    – alper
    Aug 5 at 12:06
  • @alper See my edit. This should work. Aug 5 at 13:04
  • The key /tikz/text width "will put the text of a node in a box of the given width (something akin to a {minipage} of this width, only portable across formats)". This might be used here. (However, the vertical spacing is different then.) Aug 5 at 13:21
3

A solution using tabularray package (tables) and tikz:

\documentclass[12pt]{article}  
\usepackage{tikz}  
\usepackage{tabularray}  
\UseTblrLibrary{counter}  
\newcounter{tabitem}  
\newcommand{\tabitem}{\stepcounter{tabitem}\makebox[21pt][r]{\arabic{tabitem}.\;\,}} % for the distance of the labels   
\begin{document}  
    \begin{tikzpicture}  
        \draw (0,0) circle (2) node[above,yshift=2cm] {%  
            \begin{tblr}{colspec={Q[7cm,m]},rows={0.6cm,m},hlines,hline{2-4}={0pt},vlines}  
                \tabitem This is the first item\\  
                \tabitem This is the second\\  
                \tabitem This is the third \\  
                \tabitem This is a node for the circle\\    
            \end{tblr}};  
    \end{tikzpicture}  
\end{document}

Hope this helps!

3
  • Interesting approach! However, I get an enumeration with 10., 12., 14., 16. Aug 4 at 13:01
  • Did you use the code as it is?
    – Miltos P.
    Aug 4 at 13:04
  • 1
    Yes, but I did not use the most current version of tabularray. With version 2022C it works. Aug 4 at 13:10
3

This version uses \fbox and varwidth.

\documentclass{article}
\usepackage{varwidth}
\begin{document}

\noindent\fbox{\hspace{\dimexpr 1em-\labelwidth}% allow 1em for label
\begin{varwidth}{0.9\columnwidth}
  \begin{enumerate}
    \item Pending \texttt{SIGINT} and \texttt{SIGQUIT} unblocked 
    \item Kernel invokes hanlder for \texttt{SIGINT} 
    \item \texttt{SIGINT} handler makes a system call
    \item Kernal invokes handler for \texttt{SIGQUIT} 
  \end{enumerate}%
\end{varwidth}}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.