使一个环境流畅地融入另一个环境,没有空白

使一个环境流畅地融入另一个环境,没有空白

我现在有这个设计。

在此处输入图片描述

然而,当你拥有很多这样的物品时,它们会分散你的注意力。

我建议将答案与问题放在同一条线上,例如

问题 41乱码答案 38再次出现 Lorem。

我的短信

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

我正在思考如何正确更改这些问题和答案环境。我不想删除它们,因为它们为我提供了灵活性。我只想删除空行,并将答案放在问题后面。

如何消除两个环境之间的空间?

答案1

我建议使用frametitle环境mdframed来显示问题并使用正文来显示答案:

在此处输入图片描述

笔记:

  • 您也许可以选择更好的颜色。
  • 如果需要,还需要添加编号。

代码:

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

答案2

在此处输入图片描述

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

答案3

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}

在此处输入图片描述

相关内容