1

I'm trying to recreate something similar to this:

Example

Where the numbering is encased inside its own box, and the content in another.

I know I could probably use a table but I was wondering if there is another way, possibly making a custom enumerate environment to accomplish this.

I did find a similar implementation, but it was accomplished by wrapping the item itself which leaves gaps between the items.

Here is some code i've tried, but it doesnt include the vertical line:

\usepackage{enumitem}
\usepackage{array}

\def\twodigits#1{%
  \ifnum#1<10 0\fi
  \number#1}

\fbox{
\begin{minipage}{6.5in}
\centering
\textbf{Title}
\begin{enumerate}[label={\protect\twodigits{\theenumi}.}]
  \item My first item
  \item My second item
 \end{enumerate}
\end{minipage}
}
Bernard
  • 271,350
  • 1
    Welcome to TeX.SX! It would be great if you could show us what you have tried. Posting a minimal working example that indicates what you are trying to do makes it easier for people to understand what you want. It also makes it easier for people to help you, since they have some code to start from, and hence much more likely that some one will try to help you. –  Mar 01 '20 at 12:20
  • 2
    Why not use a table? Also, why do this at all? The lines don't add any clarity. Rather, they distract and introduce an unnecessary separation between the item numbers and the item texts. – schtandard Mar 01 '20 at 13:36
  • @schtandard I completely agree, unfortunately it is part of a layout request. – Justin Dalrymple Mar 01 '20 at 14:10

2 Answers2

0

I'd suggest using a tabular for the task. In the following example, I have combined the magicrownumber originally from here with your \twodigits command to automatically number the rows in the table. I have also used the calc package in order to calculate the width of the second column to make the whole table fit perfectly into the available text width.

enter image description here

\documentclass{article}

\usepackage{calc}

\def\twodigits#1{%
  \ifnum#1<10 0\fi
  \number#1}

\usepackage{array,etoolbox}
\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}
\def\rownumber{}
\usepackage{makecell}

\begin{document}

\noindent
\begin{tabular}{|@{\makebox[2.5em][r]{\rownumber\space}} | p{\textwidth-2\tabcolsep-2.5em-3\arrayrulewidth}|}
\hline
  \makecell{Title}
  \gdef\rownumber{\stepcounter{magicrownumbers}\protect\twodigits{\arabic{magicrownumbers}}.} \\
  My first item\\
  My second item\\
  \hline
\end{tabular}


\end{document}
leandriis
  • 62,593
0

If your enumeration is long, you can use longtable

\documentclass{article}
\usepackage{longtable,array}

\usepackage{lipsum}

\newcommand{\justinitem}{%
  \stepcounter{justinitem}%
  \ifnum\value{justinitem}<10 0\fi\arabic{justinitem}.%
}
\newcounter{justinitem}

\newenvironment{justinenumerate}[1]
 {
  \setcounter{justinitem}{0}%
  \newcommand{\jitem}{&}%
  \begin{longtable}{|>{\justinitem} w{r}{2em}|
    p{\dimexpr\textwidth-4\tabcolsep-3\arrayrulewidth-2em}|}
  \hline
  \multicolumn{1}{|c|}{} & \multicolumn{1}{c|}{\bfseries #1} \\
 }
 {\hline\end{longtable}}

\begin{document}

\lipsum[3]

\begin{justinenumerate}{Title}
\jitem text for the first item text for the first item 
  text for the first item text for the first item 
  text for the first item text for the first item 
  text for the first item \\
\jitem text for the second item \\
\end{justinenumerate}

\lipsum

\end{document}

Remember to add \\ at the end of each item.

enter image description here

egreg
  • 1,121,712
  • This is perfect! Thank you. Is there a way to remove the prefix/suffix vertical space?

    EDIT: I found the answer to my question, using:

     \setlength{\LTpre}{0pt}
    
    – Justin Dalrymple Mar 01 '20 at 17:48
  • @JustinDalrymple Add, before \begin{longtable}, \setlength{\LTpre}{0pt}\setlength{\LTpost}{0pt}. – egreg Mar 01 '20 at 17:55
  • I spoke too soon. I applied that change, but the prefix space remains. I've even tested it on an empty document to make sure other items were not affecting the spacing. hmm... – Justin Dalrymple Mar 01 '20 at 17:59
  • @JustinDalrymple I tested my suggestion and it removes the space; however, 0pt is too small, probably \topsep is a better choice. – egreg Mar 01 '20 at 18:02
  • You're correct! The problem was due to something else. Thank you! – Justin Dalrymple Mar 01 '20 at 18:12