2

this is kind of a follow up of this question, where someone asked how to create a box around a few items in an itemize environment. I'm facing a similar issue, but my case is a little bit more complex, as I want to be able to generate things like in the image below.

enter image description here

I tried to adapt the solution in the aforementioned link, but it doesn't work since the left markings are overwritten when I add more of them.

Does anyone have a solution to this?

--- EDIT ---

This is what I have so far, which works well without nested boxes

\documentclass{article}
\usepackage[a4paper,top=3cm,left=2.5cm,right=2.5cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{xparse}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\bitem}[3]{\makebox[#1]{#2\hfill} \quad #3}
\newcommand{\bitemL}[3]{\tikzmark{left}\makebox[#1]{#2\hfill} \quad #3}
\newcommand{\bitemR}[3]{\makebox[#1]{#2\hfill}\tikzmark{right} \quad #3}

\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[black]
      ($(left)+(-0.2em,0.9em)$) rectangle
      ($(RightPoint)+(0.2em,-0.3em)$);}
}

\makeatother

\begin{document}

    \medskip\par\noindent
    \begin{minipage}{0.4\linewidth}
        \begin{enumerate}
            \item [1.]{\bitem{2cm}{$\neg Q \rightarrow \neg P$}{$(premissa)$}}
            \item [2.]{\bitemL{2cm}{$P$}{$(hipótese)$}}
            \item [3.]{\bitem{2cm}{$\neg \neg P $}{$(\neg \neg i ~ 2)$}}
            \item [4.]{\bitemR{2cm}{$\neg \neg Q $}{$(MT ~ 1, 3)$}}
            \item [5.]{\bitem{2cm}{$P \rightarrow \neg \neg Q$}{$(\rightarrow i ~ 2,4)$}}
        \end{enumerate}
        \DrawBox[thick]
    \end{minipage}

\end{document}

This code will produce this enter image description here

5
  • Well, this will be rather straightforward with the tikzmark library (or even without) provided you go ahead and bake an MWE in which the text without these boxes is produced. Typing this up is not something many like to do.
    – user121799
    Commented Sep 10, 2018 at 23:46
  • I don't need the whole thing typed, only a way to understand how to generate stuff like in the image. Even an example with two boxes and one line in each would suffice. I tried for a long time and could not figure it out.
    – BrunoB
    Commented Sep 11, 2018 at 0:04
  • It's always good to show what you have tried and to give people some code to start from - -this both makes it easier for people to help you and more likely that some one will.
    – user30471
    Commented Sep 11, 2018 at 0:11
  • Maybe easylist is a possible starting point.
    – Symbol 1
    Commented Sep 11, 2018 at 0:19
  • @Symbol1 thanks for the suggestion, I didn't know this library. I'll check it out
    – BrunoB
    Commented Sep 12, 2018 at 15:16

1 Answer 1

4

I really focus on the boxes here, ignoring nice suggestions like easylist by Symbol 1. This is mainly to advertize the new version of LoopSpaces tikzmark library, which can be found here. This library contains a new command, \tikzmarknode, which can be used to make an ordinary element of some text a node. Amazingly, it will check whether or not you are in math mode, and typeset the text accordingly. You can thus define some nodes and use the fit library to draw boxes around them. These boxes will always contain the nodes, so you may want to set them at some extremal positions. And you can nest these fits, which may help you to have nested boxes, as in the following example. Of course, there is a lot of room for improvement of the layout.

\documentclass{article}
\usepackage{amssymb,tikz}
\usetikzlibrary{tikzmark,fit}
\begin{document}
\begin{enumerate}
 \item \qquad $\tikzmarknode{q1}{q}\to r$ \hfill hypothesis\\[2mm]

 \item \qquad\qquad $\tikzmarknode{neg1}{\neg q\to\neg p}$ \hfill hypothesis\\[2mm]

 \item \qquad\qquad\qquad $\tikzmarknode{p1}{p}$ \hfill hypothesis

 \item \qquad\qquad\qquad $\neg\neg p$ \hfill hypothesis

 \item \qquad\qquad\qquad $\tikzmarknode{neg2}{\neg\neg p}$ \hfill hypothesis\\[2mm]

 \item \qquad\qquad $p\to \tikzmarknode{r2}{r}$ \hfill hypothesis\\[2mm]

 \item \qquad $(\neq p\to \neq q)\to p\to \tikzmarknode{r1}{1}$
\end{enumerate}
\begin{tikzpicture}[overlay,remember picture]
\node[draw,inner sep=9pt,fit=(q1)(r1)]{};
\node[draw,inner sep=9pt,fit=(neg2)(p1)](fit2){};
\node[draw,inner sep=9pt,fit=(neg1)(r2)(fit2)]{};
\end{tikzpicture}
\end{document}

enter image description here

3
  • It didn't work for me, I think that this version is still not updated in MacTeX
    – BrunoB
    Commented Sep 17, 2018 at 23:12
  • @BrunoB Yes, that's why I shared this link.
    – user121799
    Commented Sep 17, 2018 at 23:24
  • I tried that but it was not working. I now managed to find what I was doing wrong. It's working now with this new version of tikzmark. Thank you very much!
    – BrunoB
    Commented Sep 23, 2018 at 19:40

You must log in to answer this question.

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