You need to save the enumerate
contents in a \vbox
:
\setbox\enumbox\vbox{% …
Though, the \centering
won’t work because the box is—due to enumerate
’s nature— \linewidth
wide.
Using it without \centering
results in an overfull \hbox
because the paragraph indention is inserted as usual.
Solution A
It seems, that in your case you simply could define a macro as
\newcommand*{\enummacro}{\begin{enumerate} … \end{enumerate}}
and use that inside a TikZ node. Advantage: The node would not be \linewidth
wide but only as wide as you would have specified.
Solution B
You could measure the width of the list elements (assuming that they all fit on one line width-wise).
Here, I opted for an easier list defining and processing solution, namely
\newcommand*{\mylist}{Title,Abstract,Keywords,Outline}
The \mylist
macro only contains the comma-separated elements.
The \getWidthOf
macro needs \tikz@textfont
and the smuggle macro to be usable inside a tikzpicture
(no warranties here).
Solution C
As the enumerate
environment introduces vertical and horizontal space which with I do not want to deal and also because the following looks better and is easier to maintain, yet another solution but with a simple tabular
.
Code A (enumerate
with guessed width)
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\newcommand{\enummacro}{%
\begin{enumerate}
\item Title
\item Abstract
\item Keywords
\item Outline
\end{enumerate}}
\newsavebox\enumbox
\begin{document}
\setbox\enumbox\vbox{\enummacro}
\noindent\usebox\enumbox
\begin{tikzpicture}
\node[draw, text width=8em, align=center] {\enummacro};
\end{tikzpicture}
\end{document}
Output (enumerate
with guessed width)

Solution B (properly measured enumerate
)
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\newcommand*{\mylist}{Title,Abstract,Keywords,Outline}
\newlength{\widthOfWidestElement}
\makeatletter
\def\qrr@smuggle@length@through@interruptpgfpicture#1\endpgfinterruptpicture{%
\edef\@tempa{\the#1}%
\expandafter\endpgfinterruptpicture\expandafter#1\@tempa}
\newcommand*{\getWidthOf}[1]{%
\pgfinterruptpicture
\setlength{\widthOfWidestElement}{0pt}%
\@for\@element:=#1\do{%
\sbox0{\tikz@textfont\@element}%
\ifdim\wd0>\widthOfWidestElement\widthOfWidestElement=\wd0\fi
}%
\qrr@smuggle@length@through@interruptpgfpicture\widthOfWidestElement
\endpgfinterruptpicture
\advance\widthOfWidestElement\itemindent
\advance\widthOfWidestElement\leftmargin
\advance\widthOfWidestElement\rightmargin
}
\newcommand*{\makeEnumerate}[1]{%
\enumerate % maybe better output with
% \parskip\z@
\@for\@element:=#1\do{%
\item \@element
}
\endenumerate
}
\makeatother
\begin{document}
\begin{tikzpicture}
\getWidthOf{\mylist}
\node[draw, text width=\widthOfWidestElement, align=center] {\makeEnumerate\mylist};
\end{tikzpicture}
\end{document}
Output B (properly measured enumerate
)

Code C (tabular
)
\documentclass[a4paper,12pt]{article}
\usepackage{tikz,array}
\newcommand*{\mylist}{Title,Abstract,Keywords,Outline}
\makeatletter
\newcommand*{\makeFakeEnumerate}[1]{%
\begingroup
\def\@temptabbody{}%
\setcounter{enumi}{0}%
\@for\@element:=#1\do{%
\expandafter\g@addto@macro\expandafter\@temptabbody\expandafter{\expandafter&\@element \\}}%
\tabular{>{\refstepcounter{enumi}\theenumi.}rl}
\@temptabbody
\endtabular
\endgroup
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[draw] {\makeFakeEnumerate\mylist};
\end{tikzpicture}
\end{document}
Output C (tabular
)
