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 this design at the moment.

enter image description here

However, when you have many of those, they distract much.

I propose to have Answer just on the same line with Question like

Question 41 Lorem ipsun. Answer 38 Lorem again.

My tex

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

\newtheorem{question}{Question}
\let\masiquestion\question
\AtBeginDocument{%
  \let\umquestion\question
  \let\question\masiquestion
}
\newtheorem{answer}{Answer}
\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20
}
\surroundwithmdframed[style=ans]{answer}

\usepackage{environ}
\usepackage{ifthen}
\newboolean{answers}
\setboolean{answers}{true}  %%% uncomment 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
        }%
}%


\begin{document}
\begin{question}
Why is the pressure same in Arteries and aorta?
\end{question}
\begin{answer}
Because they do not coil (only arch of aorta), so the Frank-Starling equation does not hold but Laplace law instead.
Laplace law is the reason why you can have the same pressure in aorta (big) and arteries (small), because the pressure depends inversely on the pressure.
\end{answer}

\end{document}

I am thinking what would be the right way of changing these Question and Answer environments. I do not want to remove them because they offer me flexibility. I just want to remove the empty line and put the answer flowing just flowing after the question.

How can you remove the space between the two environments?

share|improve this question
    
question being in the color box too? –  percusse Mar 13 at 20:38
    
The \tcolorbox package might be worth to look at. –  Christian Hupfer Mar 13 at 20:40
    
@percusses color box is not necessary. It can be easily disabled. The easy way to read is most important without distracting the reader much. –  Masi Mar 13 at 20:45

3 Answers 3

up vote 6 down vote accepted

I would recomend using the frametitle of the mdframed environment to show the question and the body to show the answer:

enter image description here

Notes:

  • You can probably select better colors.
  • Also need to add the numbering if that is required.

Code:

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

\mdfdefinestyle{ans}{
  linecolor=cyan,
  backgroundcolor=yellow!20,
    frametitlebackgroundcolor=green!40,
    frametitlerule=true,
}

\newenvironment{question}[1]{%
    \begin{mdframed}[style=ans,frametitle={Question: #1}]
}{%
    \end{mdframed}%
}%


\begin{document}
\begin{question}{Why is the pressure same in Arteries and aorta?}
    Because they do not coil (only arch of aorta), so the Frank-Starling equation does not hold but Laplace law instead.
    Laplace law is the reason why you can have the same pressure in aorta (big) and arteries (small), because the pressure depends inversely on the pressure.
\end{question}
\begin{question}{Why is the pressure same in Arteries and aorta?}
    Because they do not coil (only arch of aorta), so the Frank-Starling equation does not hold but Laplace law instead.
    Laplace law is the reason why you can have the same pressure in aorta (big) and arteries (small), because the pressure depends inversely on the pressure.
\end{question}
\end{document}
share|improve this answer
    
I had conflicting packages - problem solved. Thank you for your answer! –  Masi Mar 14 at 6:35

enter image description here

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

\newtheorem{question}{Question}

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


\makeatletter
\def\endquestion{\ifhmode\unskip\fi\begingroup\let\par\relax}
\def\answer{\endgroup\let\par\endgraf
\def\@currenvir{answer}\quad\textbf{Answer:\nolinebreak[3] }\ignorespaces}
\makeatother

%\surroundwithmdframed[style=ans]{answer}

\begin{document}
\begin{question}
Why is the pressure same in Arteries and aorta?
\end{question}
\begin{answer}
Because they do not coil (only arch of aorta), so the Frank-Starling equation does not hold but Laplace law instead.
Laplace law is the reason why you can have the same pressure in aorta (big) and arteries (small), because the pressure depends inversely on the pressure.
\end{answer}

\end{document}
share|improve this answer

With tcolorbox:

\documentclass{article}
\usepackage[most]{tcolorbox}

\newtcolorbox[auto counter,number within=section]{question}[2][]{%
colback=magenta!15!white,colframe=blue!40!green,fonttitle=\bfseries,
title=Question.~\thetcbcounter: #2,#1}


\begin{document}
\section{Some section}

\begin{question}{Why is the pressure same in Arteries and aorta?}
    Because they do not coil (only arch of aorta), so the Frank-Starling equation does not hold but Laplace law instead.
    Laplace law is the reason why you can have the same pressure in aorta (big) and arteries (small), because the pressure depends inversely on the pressure.
\end{question}
\begin{question}{Why is the pressure same in Arteries and aorta?}
    Because they do not coil (only arch of aorta), so the Frank-Starling equation does not hold but Laplace law instead.
    Laplace law is the reason why you can have the same pressure in aorta (big) and arteries (small), because the pressure depends inversely on the pressure.
\end{question}
\end{document}

enter image description here

share|improve this answer

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.