0
  1. doesn't go in box
  2. goes in box
  3. goes in box
  4. doesn't go in box
  5. the numbers don't go in box

I'm using \begin{enumerate} for the list.

lockstep
  • 250,273
  • I think you have to make more clear your question. Do you want the texts (and only the texts) in 2 and 3 to be in a box (one box for both) but 1 4 and 5 to be outside of it? – koleygr Aug 28 '17 at 20:35

1 Answers1

2

I took one half of this solution to achieve what you want to have. See the linked solution for more details on how you can optimize that.

\documentclass{article}
\usepackage{xparse}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\makeatletter
\NewDocumentCommand{\DrawBox}{s O{}}{%
    \tikz[overlay,remember picture]{
    \IfBooleanTF{#1}{%
        \coordinate (RightPoint) at ($(left |- right)+(\linewidth-\labelsep-\labelwidth,0.0)$);
    }{%
        \coordinate (RightPoint) at (right.east);
    }%
    \draw[red,#2]
      ($(left)+(-0.2em,0.9em)$) rectangle
      ($(RightPoint)+(0.2em,-0.3em)$);}
}
\makeatother

\begin{document}

\begin{enumerate}
    \item \tikzmark{left}doesn't go in box
    \item goes in box\hspace{1cm}\tikzmark{right}\DrawBox[thick,red]
    \item \tikzmark{left}goes in box
    \item doesn't go in box\tikzmark{right}\DrawBox[dashed, very thick,blue]
    \item the numbers don't go in box
\end{enumerate}

\end{document}

enter image description here

Note: You may need to run LaTeX twice to get the correct positions.

Tiuri
  • 7,749