4

How to make enumerate items and a table side by side like the effect in the image which is from CLRS P.61. correct example

I have tried to make every row a table in each enumerate item, but the effect is not the same as what I expect.

And manually adding a. b. c. in the first column of a table could not solve the problem either because it will make the indentation wrong. Here is a MWE to show the wrong indentation.

\documentclass{article}

\usepackage{array}
\usepackage{showframe}
\usepackage{enumitem}
\usepackage{amsmath}

\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash$}p{#1}<{$}}

\begin{document}

$\begin{array}{L{1em}C{3em}*{6}{C{3em}|}}
& A & B & O & o & \Omega & \omega & \Theta \\ \hline
a. & {\lg^k{n}} & n^{\epsilon} &  &  &  &  &  \\ \hline
b. & n^k & c^n &  &  &  &  &  \\ \hline
c. & \sqrt{n} & n^{\sin{n}} &  &  &  &  &  \\ \hline
\end{array}$

\begin{enumerate}[label=\textbf{\textit{\alph*}}.]
\item $\displaystyle\lim_{n \to \infty} (1+\frac{1}{n})^n = e$
\item $\displaystyle\lim_{n \to \infty} (1+\frac{1}{n})^n = e$
\item $\displaystyle\lim_{n \to \infty} (1+\frac{1}{n})^n = e$
\end{enumerate}

\end{document}

wrong indentation

In the image above ,the first red line could not be horizontally aligned with the second red line.

4
  • 1
    I guess adding the letters in their own column is the easiest way to go. What do you mean by "it will make the indentation wrong"? Please edit your question and add a minimal working example (MWE), including the additional column, and describe precisely what goes wrong.
    – jarauh
    Nov 23, 2015 at 16:13
  • Thank you for your suggestion. I add a MWE to show the wrong indentation after editing the problem description.
    – Christophe
    Nov 24, 2015 at 5:18
  • @Christophe: You completely changed the question since in the first version the was no separate enumeration environment :-(
    – user31729
    Nov 24, 2015 at 8:53
  • @ChristianHupfer Really sorry for only obscurely mentioning about the indentation problem in the first version!
    – Christophe
    Nov 24, 2015 at 9:03

1 Answer 1

6

This uses a new column type called E (like enumerate) and a counter called rowcounter which increases in each row, the first row is omitted here. The table column is left aligned, but r - type might be better!

Please note that this will fail after 26 rows of course since the \alph output cannot handle counter values larger than 26. The \alphalph command from alphalph package could be useful then.

Please fill in in the math content yourself.

\documentclass{article}

\usepackage{array}

\newcounter{rowcounter}
\newcolumntype{E}{>{\bfseries \ifnum\value{rowcounter} > 0 \alph{rowcounter}.\fi\stepcounter{rowcounter}}l}
\begin{document}

\begin{tabular}{E*{7}{c}}
  & A & B & C & D & E & F & G\tabularnewline
  & \tabularnewline
  & \tabularnewline
  & \tabularnewline
  & \tabularnewline
\end{tabular}



\end{document}

enter image description here

Update

\documentclass{article}

\usepackage{array}
\usepackage{showframe}
\usepackage{enumitem}
\usepackage{amsmath}

\newcounter{rowcounter}
\newcolumntype{D}{>{\ifnum\value{rowcounter} > 0 \text{\textbf{\textit{\alph{rowcounter}}}.}\fi\stepcounter{rowcounter}}r}
\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash$}p{#1}<{$}}


\newlength{\enumindent}
\setlength{\enumindent}{\leftmargin}
\addtolength{\enumindent}{1.7\tabcolsep}



\begin{document}
$
\begin{array}{DC{3em}*{6}{C{3em}|}}
   & A & B & O & o & \Omega & \omega & \Theta \\ \hline
 & {\lg^k{n}} & n^{\epsilon} &  &  &  &  &  \\ \hline
 & n^k & c^n &  &  &  &  &  \\ \hline
 & \sqrt{n} & n^{\sin{n}} &  &  &  &  &  \\ \hline
\end{array}
$

\begin{enumerate}[label=\textbf{\textit{\alph*}}.,leftmargin=\enumindent]
\item $\displaystyle\lim_{n \to \infty} (1+\frac{1}{n})^n = e$
\item $\displaystyle\lim_{n \to \infty} (1+\frac{1}{n})^n = e$
\item $\displaystyle\lim_{n \to \infty} (1+\frac{1}{n})^n = e$
\end{enumerate}

\end{document}

enter image description here

5
  • Thank you for your solution. But like I said, it also has the indentation problem. I made a WME to show that. I want the first group of enumerate items to be vertically aligned with the second group.
    – Christophe
    Nov 24, 2015 at 4:40
  • @Christophe: You rather want horizontal alignment, not the vertical one!
    – user31729
    Nov 24, 2015 at 8:54
  • @Christophe: See my update please
    – user31729
    Nov 24, 2015 at 9:24
  • Thanks for update. Except for manually setting the rowcounter to zero when I have more than one this kind of table, the solution is perfect.
    – Christophe
    Nov 24, 2015 at 12:31
  • Well, how should TeX know you want to use the rowcounter stuff? I can think about it, but at the moment I am occupied with other issues ;-)
    – user31729
    Nov 24, 2015 at 12:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .