最后编辑:

最后编辑:

我有环境问题(描述于明确区分章节内的区块) 和答案块。我希望答案块与问题块相同,但其中的文本是颠倒的。

最小示例

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
  % , rotatebox
}
\surroundwithmdframed[style=ans]{answer}


\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{answer}
Lorem
\end{answer}
\end{document}

我明白了

在此处输入图片描述

在 Answer 环境中如何让文本颠倒? 我希望文本难以阅读,这样读者在寻找答案之前会尝试自己回答问题。任何其他包含答案的方式也是可以接受的,因为我不确定哪种方式最好。不过,我个人希望这些答案在问题之后的绘制代码中可见。

答案1

请参阅最后一次编辑以了解自动切换

您可以Answer根据您的answer环境定义一个新的环境:

\usepackage{environ}
\NewEnviron{Answer}
{%
\noindent
\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\begin{answer}
\BODY
\end{answer}%
\end{minipage}%
}%
}%

完整代码:

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
  % , rotatebox
}
\surroundwithmdframed[style=ans]{answer}

\usepackage{environ}
\NewEnviron{Answer}
{%
\noindent
\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\begin{answer}
\BODY
\end{answer}%
\end{minipage}%
}%
}%


\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{Answer}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{Answer}
\end{document}

在此处输入图片描述

是否难以阅读?让我们开始吧:

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
  % , rotatebox
}
\surroundwithmdframed[style=ans]{answer}

\usepackage{environ}
\NewEnviron{Answer}
{%
\noindent
\reflectbox{\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\begin{answer}
\BODY
\end{answer}%
\end{minipage}%
}%
}}%


\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{Answer}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{Answer}
\end{document}

在此处输入图片描述

\NewEnviron{Answer}
{%
\noindent
\scalebox{1}[-1]{\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\begin{answer}
\BODY
\end{answer}%
\end{minipage}%
}%
}}%

一个人

在此处输入图片描述

但要小心那些带镜子的人;)

事实上,\scalebox仅使用 ,无需使用 即可实现前面的方向\rotatebox

最后编辑:

如果你想自动显示/隐藏答案,这里有一种方法。请参阅注释的代码行

%\setboolean{answers}{true}  %%% uncomment to show answers properly
\setboolean{answers}{false}  %%% comment to show answers properly

完整代码:

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
  % , rotatebox
}
\surroundwithmdframed[style=ans]{answer}

\usepackage{environ}
\usepackage{ifthen}
\newboolean{answers}
%\setboolean{answers}{true}  %%% uncomment to show answers properly
\setboolean{answers}{false}  %%% comment to show answers properly


\ifthenelse{\boolean{answers}}%
  {%
  \NewEnviron{Answer}
    {%
    \noindent
    \begin{minipage}[t]{\linewidth}
        \begin{answer}
            \BODY
        \end{answer}%
    \end{minipage}%  here put what the command has to do when outside
        }%
}%
    {\NewEnviron{Answer}
    {%
    \noindent
    \scalebox{1}[-1]{%
    \noindent
    \begin{minipage}[t]{\linewidth}
        \begin{answer}
            \BODY
        \end{answer}%
    \end{minipage}%
       }%
    }%
}%


\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{Answer}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{Answer}
\end{document}

\setboolean{answers}{false}

我们得到:

在此处输入图片描述

\setboolean{answers}{true}

我们得到:

在此处输入图片描述

带有可选参数

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
  % , rotatebox
}
\surroundwithmdframed[style=ans]{answer}

\usepackage{environ}

\def\invert{-1}
 \NewEnviron{Answer}[1][1]%
    {%
    \noindent
    \scalebox{1}[#1]{%
    \noindent
    \begin{minipage}[t]{\linewidth}%
        \begin{answer}
            \BODY
        \end{answer}%
    \end{minipage}%
       }%
    }%

\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{Answer}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{Answer}

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{Answer}[\invert] 
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{Answer}
\end{document}

答案2

一个想法是定义一个新环境,将答案内容放在 TikZ 中\node并旋转它:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ}
\usepackage{lipsum}

\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
}
\surroundwithmdframed[style=ans]{answer}

\NewEnviron{rotanswer}{%
  \begin{tikzpicture}
  \node[rotate=180,inner sep=0pt] {\parbox{\linewidth}{%
  \begin{answer}
  \BODY
  \end{answer}}};
\end{tikzpicture}%
}

\begin{document}

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{rotanswer}
Lorem
\end{rotanswer}

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{rotanswer}
\lipsum[4]
\end{rotanswer}

\end{document}

在此处输入图片描述

你可以让事情对那些决定阅读答案的人来说变得更加困难;-)

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ}
\usepackage{lipsum}

\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
}
\surroundwithmdframed[style=ans]{answer}

\NewEnviron{rotanswer}{%
  \begin{tikzpicture}
  \node[rotate=180,inner sep=0pt,xscale=-1] {\parbox{\linewidth}{%
  \begin{answer}
  \BODY
  \end{answer}}};
\end{tikzpicture}%
}

\begin{document}

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{rotanswer}
Lorem
\end{rotanswer}

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{rotanswer}
\lipsum[4]
\end{rotanswer}

\end{document}

在此处输入图片描述

答案3

这是另一个解决方案,它不需要environ包,因为它使用 anewsavebox来代替。

与其他答案不同的部分是

\makeatletter
\newsavebox{\@my@box}
\newenvironment{Answer}%
{%
    \noindent
    \begin{lrbox}{\@my@box}%
    \begin{minipage}[t]{\linewidth}
    \begin{answer}
}%
{%
    \end{answer}%
    \end{minipage}%
    \end{lrbox}%
    \rotatebox{180}{\usebox{\@my@box}}
}%

如你所见,它将环境的内容存储在其中,\@my@box然后使用rotateboxgraphicx包,它由mdframedtikz

输出与其他答案相同。

% arara: pdflatex
\documentclass{article}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
  linecolor=cyan,
  backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
}
\surroundwithmdframed[style=ans]{answer}

\makeatletter
\newsavebox{\@my@box}
\newenvironment{Answer}%
{%
    \noindent
    \begin{lrbox}{\@my@box}%
    \begin{minipage}[t]{\linewidth}
    \begin{answer}
}%
{%
    \end{answer}%
    \end{minipage}%
    \end{lrbox}%
    \rotatebox{180}{\usebox{\@my@box}}
}%


\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\begin{Answer}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{Answer}
\end{document}

相关内容