环绕图定位

环绕图定位

我想做一个多解决方案环境, 像那样:

在此处输入图片描述

我使用这个代码来实现奇特的开始和结束:

\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}

但我有这个问题:

在此处输入图片描述

我做错了什么?

答案1

更新后的版本:

我明白你想让“End # solution”在段落中浮动多行。我对 TeX 的魔力还不够熟练,无法在段落中获得两个浮动让一个位于左上角,另一个位于右下角。我建议创建一个新问题,专门用于在一个段落内放置两个浮动元素(一个位于开头,一个位于结尾)。

我使用/定义了一个命令借用这个答案用于水平线。我对其进行了修改,删除了颜色参数。

镜像文本 I借用这个答案。答案中还有关于如何修改反射的更多详细信息。

\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}

使用 yshift 更新版本图片

原始版本:

tikz正如评论中提到的那样,您不需要为此使用。您实际上只需要 的rotatingEnd # solution。我没有制作出您图片中完全相同的东西,因为解决方案 1 和解决方案 2 之间不一致……希望我的假设能够解决您正在寻找的问题:

\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}

我使用xparse只是为了方便\NewDocumentEnvironment,以防您稍后决定更改参数的数量或可选性。另外,我相信不用 也可以做到这一点wrapfig。但为了得到你想要的(占据Begin # solution段落的两个行高),它似乎wrapfig效果很好。

输出如下:

解决方案开始和结束 fbox

相关内容