\newenvironment 中的 \reflectbox

\newenvironment 中的 \reflectbox

\reflectbox{}我在 a 中使用的命令存在以下问题\newenvironment{}:它不执行任何操作。这是我的代码:

\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{newtxtext}
\usepackage[libertine]{newtxmath}
\usepackage{graphicx}

\newenvironment{solution}[1]{\reflectbox{#1}}

\begin{document}

    Hello \reflectbox{World}.

    \begin{solution}
        This should not be readable, but it is.
    \end{solution}

\end{document}

非常感谢您的任何建议。谢谢!

答案1

你应该先把内容收集到一个盒子里,用minipage里面的东西来应对段落。

然后你就可以反射这个盒子了。

\documentclass{article}
\usepackage{graphicx}

\newsavebox{\solutionbox}
\newenvironment{solution}
 {%
  \par\addvspace{\topsep}%
  \begin{lrbox}{\solutionbox}\begin{minipage}{\textwidth}%
 }
 {%
  \end{minipage}\end{lrbox}%
  \noindent\reflectbox{\usebox{\solutionbox}}%
  \par\addvspace{\topsep}%
 }

\begin{document}

Hello \reflectbox{World}.

\begin{solution}
This should not be readable, and it isn't.
This should not be readable, and it isn't.
This should not be readable, and it isn't.
This should not be readable, and it isn't.
This should not be readable, and it isn't.
This should not be readable, and it isn't.
\end{solution}

\end{document}

在此处输入图片描述

答案2

带有包的解决方案environ

\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{newtxtext}
\usepackage[libertine]{newtxmath}
\usepackage{graphicx}
\usepackage{environ}

\NewEnviron{solution}{\reflectbox{\BODY}}

\begin{document}

    Hello \reflectbox{World}.

    \begin{solution}
        This should not be readable, but it is.
    \end{solution}
\end{document}

另一种解决方案adjustbox,无需environ

\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{newtxtext}
\usepackage[libertine]{newtxmath}
\usepackage{graphicx}
\usepackage{adjustbox}

\newenvironment{solution}{\adjustbox{reflect}\bgroup}{\egroup}

\begin{document}

Hello \reflectbox{World}.

\begin{solution}
    This should not be readable, but it is.
\end{solution}
\end{document}

在此处输入图片描述

还有一种不需要其他软件包的方法,但是\savebox

\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{newtxtext}
\usepackage[libertine]{newtxmath}
\usepackage{graphicx}

\newsavebox\mybox

\newenvironment{solution}{\savebox\mybox\bgroup\vbox\bgroup}{\egroup\egroup\reflectbox{\usebox{\mybox}}}

\begin{document}

    Hello \reflectbox{World}.

    \begin{solution}
        This should not be readable, but it is.

        Some other text
    \end{solution}
\end{document}

在此处输入图片描述

相关内容