tabular to look identical to a list with and without parindent
You can try the listliketab package:
\documentclass{article}
\usepackage[parfill]{parskip}% <--- should work with or without this package.
\usepackage{showframe}
\usepackage{array}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{tikz}
%% http://tex.stackexchange.com/questions/64982/why-is-parskip-zero-inside-a-minipage
\newlength{\currentparskip}
\setlength{\currentparskip}{\parskip}
\newcommand*{\CircledText}[2][fill=green]{%
\tikz[baseline=(char.base)]{%
\node[
shape=circle,
draw=gray, thick,
fill opacity=0.3,
text opacity=1,
inner sep=0.8pt,
outer sep=0pt,
#1
] (char) {#2};}%
}%
%% --------------------------------- List Version
\newlist{MyExample}{enumerate}{2}%
\setlist[MyExample,1]{parsep=\currentparskip,label=\protect\CircledText{\arabic*}}
\newcommand*{\MyList}{%
\begin{MyExample}
\item First list item
\item Second list item
\end{MyExample}}%
\usepackage{listliketab}
\storestyleof{MyExample}
\newcommand\MyTabular{%
\begin{listliketab}
\def\item{\stepcounter{MyExamplei}\CircledText[fill=yellow]{\arabic{MyExamplei}}}%
\begin{tabular}{Ll}
\item& First list item \\
\item& Second list item \\
\end{tabular}
\end{listliketab}}
\begin{document}
\textbf{Horizontal Alignment: Outside Minipage}
\MyList
\MyTabular
\textbf{Horizontal Alignment: Inside Minipage}
\setlength{\currentparskip}{\parskip}% save the value
\begin{minipage}{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyList
\MyTabular
\end{minipage}%
\bigskip
\textbf{Vertical Alignment}
\begin{minipage}{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyList
\end{minipage}%
% ----------------------------
\begin{minipage}{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyTabular
\end{minipage}%
\end{document}
Result with parskip
Result without parskip
\documentclass{article}
%\usepackage[parfill]{parskip}% <--- should work with or without this package.
\usepackage{showframe}
\usepackage{array}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{tikz}
%% http://tex.stackexchange.com/questions/64982/why-is-parskip-zero-inside-a-minipage
\newlength{\currentparskip}
\newcommand*{\CircledText}[2][fill=green]{%
\tikz[baseline=(char.base)]{%
\node[
shape=circle,
draw=gray, thick,
fill opacity=0.3,
text opacity=1,
inner sep=0.8pt,
outer sep=0pt,
#1
] (char) {#2};}%
}%
%% --------------------------------- List Version
\newlist{MyExample}{enumerate}{2}%
\setlist[MyExample,1]{label=\protect\CircledText{\arabic*}}
\newcommand*{\MyList}{%
%\par\noindent% boo
\begin{MyExample}
\item First list item
\item Second list item
\end{MyExample}
}%
%% --------------------------------- Tabular Version
\newenvironment{MyExampleTabular}[2][]{%
\def\item{\refstepcounter{MyExamplei}\CircledText[fill=yellow]{\arabic{MyExamplei}}}%
\renewcommand*{\arraystretch}{1.7}%
\hspace*{\dimexpr\labelsep+\itemindent+\leftmargin-\labelwidth\relax}% <-- close
%\hspace*{\labelsep}% <-- close
\tabular[#1]{#2}%
}{%
\endtabular%
}%
\newcommand*{\MyTabular}{%
\par\noindent
\begin{MyExampleTabular}[t]{@{}l@{}>{\hspace{\labelsep}} l}
\item & First list item \\
\item & Second list item \\
\end{MyExampleTabular}
}%
\begin{document}
\textbf{Horizontal Alignment: Outside Minipage}
\MyList
\MyTabular
\textbf{Horizontal Alignment: Inside Minipage}
\setlength{\currentparskip}{\parskip}% save the value
\begin{minipage}{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyList
\MyTabular
\end{minipage}%
\bigskip
\textbf{Vertical Alignment}
\begin{minipage}[t]{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyList
\end{minipage}%
% ----------------------------
\begin{minipage}[t]{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyTabular
\end{minipage}%
\end{document}
Note I've used [t]
here to get vertical alignment correct at the top, but this will lose information about the baseline of the last item which makes vertical space at the end harder (see the documentation of l3 coffins)
The following seems to do the trick. The spacing appears to be consistent between the two both with and without parskip
. I took the liberty of adding a few more items for comparison.
\documentclass{article}
%\usepackage[parfill]{parskip}% <--- should work with or without this package.
\usepackage{showframe}
\usepackage{array}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{tikz}
%%Added in Edit to make the explicit space implicit
\makeatletter
\newlength{\arrayexplvsep}
\setlength{\arrayexplvsep}{0pt}
\def\new@argarraycr[#1]{\@argarraycr[\dimexpr#1+\arrayexplvsep\relax]}
\def\@xarraycr{\@ifnextchar [\new@argarraycr{\new@argarraycr[0pt]}}
\makeatother
%% http://tex.stackexchange.com/questions/64982/why-is-parskip-zero-inside-a-minipage
\newlength{\currentparskip}
\newcommand*{\CircledText}[2][fill=green]{%
\smash{\tikz[baseline=(char.base)]{%<=====added \smash so that different numerals do not impact line height
\node[
shape=circle,
draw=gray, thick,
fill opacity=0.3,
text opacity=1,
inner sep=0.8pt,
outer sep=0pt,
#1
] (char) {#2};}}\strut%<=====added strut for consistent height
}%
%% --------------------------------- List Version
\newlist{MyExample}{enumerate}{2}%
\setlist[MyExample,1]{label=\protect\CircledText{\arabic*}}
\newcommand*{\MyList}{%
\par\noindent
\begin{MyExample}
\item First list item
\item Second list item
\item Third list item
\item Fourth list item
\item Fifth list item
\end{MyExample}
}%
%% --------------------------------- Tabular Version
\newenvironment{MyExampleTabular}[2][]{%
\def\item{\hfill\refstepcounter{MyExamplei}\CircledText[fill=yellow]{\arabic{MyExamplei}}}%<=====added \hfill to make it right aligned (default); also changed to \refstepcounter
\unskip\vspace{\topsep}\par\noindent%<=====added the \unskip, \topsep space, and moved \par\noindent
\setlength{\arrayexplvsep}{\dimexpr\itemsep+\parsep\relax}%<=====added in Edit to define the explicit space
\tabular[#1]{#2}%
}{%
\endtabular%
}%
\newcommand*{\MyTabular}{%
\begin{MyExampleTabular}[t]{@{}p{\dimexpr\leftmargin-\labelsep\relax}@{}>{\hspace{\labelsep}}l}%%<=====added [t] and changed l to p{\dimexpr\leftmargin-\labelsep\relax}
\item & First list item\\
\item & Second list item\\
\item & Third list item\\
\item & Fourth list item\\
\item & Fifth list item%\\%<====inclusion will add space below, which throws off vertical alignment when minipage does not use [t] option.
\end{MyExampleTabular}
}%
\begin{document}
\textbf{Horizontal Alignment: Outside Minipage}
\MyList
\MyTabular
\textbf{Horizontal Alignment: Inside Minipage}
\setlength{\currentparskip}{\parskip}% save the value
\begin{minipage}{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyList
\MyTabular
\end{minipage}%
\bigskip
\textbf{Vertical Alignment}
\begin{minipage}{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyList
\end{minipage}%
% ----------------------------
\begin{minipage}{0.3\linewidth}
\setlength{\parskip}{\currentparskip}% restore the value
\MyTabular
\end{minipage}%
\end{document}
Modifications for vertical alignment:
- Added
\smash
and\strut
to the\CircledText
definition so that the label was a consistent height, regardless of the contained text (otherwise, the vertical alignment is thrown off). - Removed
\renewcommand*{\arraystretch}{1.7}
andadded explicit spacing after each item consistent withEdit: As per the OP's request, the explicit space has been made implicit (automatically included with eachenumitem
(\\[\dimexpr\itemsep+\parsep\relax]
).\\
) through a redefinition ofarray
's\@xarraycr
in the preamble and the addition of\setlength{\arrayexplvsep}{\dimexpr\itemsep+\parsep\relax}
inMyExampleTabular
. The definition was made so that explicit space could be added to the implicit defined byarrayexplvsep
through the typical[]
mechanism. - Moved
\par\noindent
into theMyExampleTabular
environment and added\vspace{\topsep}
for consistent top spacing withenumitem
.\unskip
was added to make the vertical spacing between the lists consistent in the first two tests.
Modifications for horizontal alignment (see pages 3-5 of the enumitem
manual):
- Added
\hfill
to the redefinition of\item
inMyExampleTabular
for consistency with the defaultright
label alignment inenumitem
. - Replaced
l
withp{\dimexpr\leftmargin-\labelsep\relax}
in\MyTabular
to mimic the defaultright
label alignment inenumitem
.
Without parskip
:
With parskip
: