2

I would like to make a many solution environment, like that:

enter image description here

I used this code for fancy starting and ending:

\documentclass{article}

\usepackage{environ}

\usepackage{wrapfig}

\usepackage{tikz}
\usetikzlibrary{fadings}
\usepackage{rotating}

\NewEnviron{solution}[1]
{
    \begin{wrapfigure}{l}{0.5\textwidth}    
        \begin{tikzpicture}
        \def\mytext{\textbf{begin #1 solution}}
        \tikzset{mynode/.style={anchor=south,inner sep=0}}
        \node[mynode]{\mytext};
        \node[scope fading=south,opacity=0.4,yscale=-1,mynode]{\mytext};
        \end{tikzpicture}
    \end{wrapfigure}

    \BODY   

    \begin{wrapfigure}{r}{0.5\textwidth}    

        \begin{turn}{180}
            \begin{tikzpicture}
            \def\mytext{\textbf{end #1 solution}}
            \tikzset{mynode/.style={anchor=south,inner sep=0}}
            \node[mynode]{\mytext};
            \node[scope fading=south,opacity=0.4,yscale=-1,mynode]{\mytext};
            \end{tikzpicture}
        \end{turn}

    \end{wrapfigure}
}

\begin{document}

\textbf{Problem}    problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem

\begin{solution}{1}
    solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\begin{solution}{2}
    solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\end{document}

but I have this problem:

enter image description here

What did I do wrong?

1 Answers1

2

UPDATED VERSION:

I understand that you want the "End # solution" to float over multiple lines in the paragraph. I am not skilled enough with the magic of TeX to get two floats in the paragraph and have one be at the upper left, while the other is at the lower right. I would suggest creating a new question for specifically putting two floats within a paragraph (one at the beginning and one at the end).

I used/defined a command borrowed from this answer for the horizontal rule. I modified it to remove the color argument.

The mirrored text I borrowed from this answer. There are additional details in the answer about how you can make modifications to the reflection.

\documentclass{article}

\usepackage{wrapfig}

\usepackage{rotating}

\usepackage{xparse}

\usepackage{tikz}
\usetikzlibrary{fadings}


\makeatletter
\newcommand\cfbox[2][lbrt]{%
  \begingroup
  \leavevmode
  \setbox\@tempboxa\hbox{%
    \color@begingroup
      \kern\fboxsep{#2}\kern\fboxsep
    \color@endgroup
  }%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep
  \advance\@tempdima\dp\@tempboxa
  \hbox{%
    \hskip-.5\fboxrule
    \lower\@tempdima\hbox{%
      \vbox{%
        \in@{t}{#1}%
        \ifin@
            {\hrule\@height\fboxrule}%
        \fi
        \hbox{%
          \in@{l}{#1}%
          \ifin@
            {\vrule\@width\fboxrule}%
          \fi
          \vbox{%
            \vskip\fboxsep
            \box\@tempboxa
            \vskip\fboxsep}%
          \in@{r}{#1}%
          \ifin@
            {\vrule\@width\fboxrule}%
          \fi
        }%
        \in@{b}{#1}%
        \ifin@
          {\hrule\@height\fboxrule}%
        \fi
      }%
    }%
    \hskip-.5\fboxrule
  }%
  \endgroup
}%
\makeatother

\NewDocumentEnvironment{solution}{m}
{%
    \vskip 24pt%
    \begingroup%
    \setlength{\parindent}{0pt}%
    \leftskip=2em\rightskip=2em%
    \begin{wrapfigure}[3]{l}[6pt]{8em}%
        \vskip-\baselineskip%
        \cfbox[b]{%
            \begin{tikzpicture}
                \def\mytext{Begin #1 solution}
                \tikzset{mynode/.style={anchor=south,inner sep=0,font=}}
                \node[mynode]{\mytext};
                \node[scope fading=south,opacity=0.4,yscale=-1,mynode]{\mytext};
            \end{tikzpicture}}%
    \end{wrapfigure}%
}{%
    \hspace*{\fill}\hspace*{0.5em}%
    \rotatebox{180}{%
        \hspace*{\fill}\hspace*{0.5em}%
        \raisebox{-0.5\baselineskip}{%
            \hspace*{0.5em}%
            \cfbox[t]{%
                \begin{tikzpicture}
                    \def\mytext{End #1 solution}
                    \tikzset{mynode/.style={anchor=south,inner sep=0,font=}}
                    \node[mynode]{\mytext};
                    \node[scope fading=south,opacity=0.4,yscale=-1,yshift=4,mynode]{\mytext};
                \end{tikzpicture}}}}%
    \vskip 24pt%
    \endgroup%
    \par%
}%

\begin{document}

\textbf{Problem}    problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem

\begin{solution}{1}
solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\begin{solution}{2}
solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2 solution 2 solution 2 solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2 solution 2 solution 2
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\begin{solution}{3}
solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3 solution 3 solution 3 solution 3 solution 3 solution 3
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\end{document}

Updated version picture with yshift

ORIGINAL VERSION:

You don't need to use tikz for this, as some have mentioned in comments. You really only need the rotating package for the End # solution. I did not produce exactly what is in your image, because it is inconsistent between solution 1 and solution 2... Hopefully my assumptions address what you are looking for:

\documentclass{article}

\usepackage{wrapfig}

\usepackage{rotating}

\usepackage{xparse}

\NewDocumentEnvironment{solution}{m}
{%
    \vskip 24pt%
    \begingroup%
    \setlength{\parindent}{0pt}%
    \leftskip=2em\rightskip=2em%
    \begin{wrapfigure}[2]{l}[6pt]{9em}%
        \vskip-\baselineskip\fbox{\hspace*{0.5em}{Begin #1 solution}\hspace*{0.5em}}%
    \end{wrapfigure}%
}{%
    \hspace*{\fill}\fbox{\rotatebox{180}{\hspace*{0.5em}{End #1 solution}\hspace*{0.5em}}}%
    \vskip 24pt%
    \endgroup%
    \par%
}%

\begin{document}

\textbf{Problem}    problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem problem

\begin{solution}{1}
    solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1  solution 1
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\begin{solution}{2}
    solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2  solution 2 solution 2 solution 2
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\begin{solution}{3}
    solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3  solution 3 solution 3 solution 3 solution 3 solution 3 solution 3
\end{solution}

text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text

\end{document}

I used xparse just for it's convenient \NewDocumentEnvironment, in case you decide to change the number or optionality of arguments later. Also, I believe it's possible to do this without wrapfig. But to get exactly what you wanted (with Begin # solution occupying two line heights of the paragraph), it seems wrapfig works well.

Here is the output:

solution begin and end fbox

whatisit
  • 1,870
  • 1
    As I said, I didn't want exactly the image I posted. This image was to show where I want the position of tikz images that I showed in code. I 'm really sorry about this confusion, I was very tired, so I was sleeping over the texstudio! – Kώστας Κούδας Dec 19 '18 at 06:50
  • 2
    Sleeping over the texstudio is a thing that happens yo me a lot, lately. – thymaro Dec 19 '18 at 08:05
  • @thymaro Maybe you should use an editor that is more comfortable as a pillow? At least in German, this one sounds much softer to sleep on: https://tex.stackexchange.com/questions/339/latex-editors-ides/923#923 :) – samcarter_is_at_topanswers.xyz Dec 19 '18 at 13:14
  • @ΚώσταςΚούδας ok, that part basically involves replacing the \fbox{...} with a tikzpicture. I can edit my answer with that today sometime. But before I do, I noticed your edit has a line at the bottom of the tikzpictures...while on the final one (End 2 solution) there is also a line on the right side. Can you clarify which version you want? – whatisit Dec 19 '18 at 15:22
  • @whatisit thanks a lot!!! I apologize again for the confusion... Thanks! – Kώστας Κούδας Dec 19 '18 at 22:24
  • 1
    @ΚώσταςΚούδας no worries. By the way, I noticed the "End # solution" reflection had less space than the "Begin # solution". I think this may be due to the \rotatebox or \raisebox. I was able to fix it with a yshift, and updated the code and image with the change. – whatisit Dec 19 '18 at 23:28
  • @samcarter oooo... bouncy combination, LaTeX on Gummi! – thymaro Dec 20 '18 at 06:07
  • @whatisit, the main problem for me was to have the images at the beginning and at the end of the solution's paragraph (as you can see from the image that I posted). This has already solved, so never mind for small problems in the code. Thanks a lot for your help! – Kώστας Κούδας Dec 20 '18 at 07:45