Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have environments Question (described in To clearly separate block inside a chapter) and Answer blocks. I want the Answer block be the same as as Question block but the text upside down in it.

Minimal example

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

I get

enter image description here

How can you have upside down text in the Answer environment? I want that the text is difficult to read so the readers try to answer the question themselves before looking for the answer. Any other way to include answers is also accepted, since I am not sure which is the best way to do it. I however want personally that those answer are visible in the draw code just after the question.

share|improve this question
2  
you could use \rotatebox –  Seamus Feb 22 at 12:01
9  
–1: Please always add MWEs ;-) –  Tobi Feb 22 at 12:02
    
In the linked answer which is the answer part? The one inside block? Which is the question? –  Harish Kumar Feb 22 at 12:29
    
I suggest you to add clarification: as it stands, to me is not clear at all what How can you have upside down text in such environment? does mean. –  Claudio Fiandrino Feb 22 at 12:38
1  
You don't need to load the mdframed package twice. –  Gonzalo Medina Feb 22 at 15:25

3 Answers 3

up vote 21 down vote accepted

See the last edit for automatic toggling

You can define a new environment Answer based on your answer environment:

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

Full code:

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

enter image description here

Making it to difficult to read?. Here we go:

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

enter image description here

With

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

one gets

enter image description here

but beware of those who bring mirrors ;)

In fact, with \scalebox alone, the former orientations can be achieved without using \rotatebox.

Last edit:

If you want to automatically show/hide answers here is a way. See the commented code lines

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

Full code:

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

With

\setboolean{answers}{false}

we get:

enter image description here

With

\setboolean{answers}{true}

we get:

enter image description here

With optional argument

\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}
share|improve this answer
1  
Why loading mdframed twice? –  Gonzalo Medina Feb 22 at 15:24
1  
What is the benefit of using the minipage here, instead of tikzpicture -environment, described in Gonzalo's answer? –  Masi Feb 22 at 15:34
    
@GonzaloMedina Thank you. As usual remnant. Corrected :) –  Harish Kumar Feb 22 at 22:09
3  
@Masi: minipage will allow breaking the lines, otherwise rotatebox will not. –  Harish Kumar Feb 22 at 22:12
5  
@Masi: Though your question in comment is good: What is the benefit of making it bold? (In other words: Let it be, this is not necessary, some people feel even upset with such things.) –  Speravir Feb 23 at 2:33

Here's another solution that doesn't need the environ package because it uses a newsavebox instead.

The different part compared to the other answers is

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

which, as you can see, stores the content of the environment in \@my@box and then rotates it using rotatebox from the graphicx package, which is automatically loaded by mdframed and tikz.

The output is the same as in the other answers.

% 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}
share|improve this answer
1  
Why a command with @? Should also work without. –  Speravir Feb 23 at 3:43
    
Have you run your command? I cannot get rotation of the answer by this method although I run it exactly as you have it here. –  Masi Feb 23 at 8:12
    
@Masi I always test my answers :) I just copied it into a new file and ran it again- works fine. Is your distribution up to date? –  cmhughes Feb 23 at 17:12
    
The problem was that you use the word "[A]nswer", while I used the word "answer" and "answers_original" so "\newenvironment{answer}...\begin{answer_original}...\end{answer_original}". I was confused by your notation. Thank you for simpler answer! –  Masi Feb 23 at 18:46

One idea is to define a new environment which places the answer contents inside a TikZ \node and rotates it:

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

enter image description here

you can make things even harder for someone who decides to read the answer ;-)

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

enter image description here

share|improve this answer
    
I ask your opinion about the answer which I accepted above because I think least packages used is the best way to go so code keeps simple. I know you understand this topic better than me. What are the possible drawbacks without the Environ package? –  Masi Feb 23 at 18:51
    
@Masi No drawbacks; the answer you accepted also does what you need. The only advantage of my answer compared to the others is that with TikZ, you can also apply some other effects (opacity, etc.) but if no such effects are desired, then any of the other answers is perfectly valid and does what you required, And you're right, if no "special effects" are needed, the accepted answer has economy in the use of packages. –  Gonzalo Medina Feb 23 at 19:45
    
I just noticed that I need the backgrounds with text Draft in some of my documents: tex.stackexchange.com/questions/162026/… It may come a day when your answer is best one soon again. –  Masi Feb 23 at 22:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.