自定义环境中没有结束行

自定义环境中没有结束行

我编写了一个“高级”环境,但如果我将另一个环境放入其中,就会遇到问题:

\documentclass{article}

\usepackage{amsmath,amsfonts,amssymb,amsthm} % For math equations, theorems, symbols, etc
\usepackage{thmtools}

\newif\ifadvanced % advanced environment
\advancedtrue % comment out to hide advanced environments


\newcommand{\separator}{\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}}
\newenvironment{advanced}{\ifadvanced\par\separator \small \fi}{\ifadvanced\\\separator\par\fi}

\declaretheoremstyle[%
  spaceabove=-6pt,%
  spacebelow=6pt,%
  headfont=\normalfont\itshape,%
  postheadspace=1em,%
  qed=\qedsymbol%
]{myproofstyle} 
\declaretheorem[name={Proof},style=myproofstyle,unnumbered,
]{advancedproof}

\begin{document}

\begin{advanced}
Inside advanced environment.
\begin{advancedproof}
inside proof
\end{advancedproof}
\end{advanced}
\end{document}

我可以通过在\end{advanced}和之间添加文本来解决这个问题\end{advancedproof},但一定有更好的方法来解决这个问题。我似乎找不到答案,因为我尝试在环境中添加换行符,但没有成功。

更新

所提出的代码搞乱了没有内部环境的行为:

\documentclass{article}

\usepackage{amsmath,amsfonts,amssymb,amsthm} % For math equations, theorems, symbols, etc
\usepackage{thmtools}

\newif\ifadvanced % advanced environment
\advancedtrue % comment out to hide advanced environments


\newif\ifadvanced % advanced environment
\advancedtrue % comment out to hide advanced environments


\newcommand{\separator}{\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}}
\newenvironment{advanced}{\ifadvanced\par\separator \small \fi}{\ifadvanced\vspace*{-1em}\separator\par\fi}

\declaretheoremstyle[%
  spaceabove=-6pt,%
  spacebelow=6pt,%
  headfont=\normalfont\itshape,%
  postheadspace=1em,%
  qed=\qedsymbol%
]{myproofstyle} 
\declaretheorem[name={Proof},style=myproofstyle,unnumbered,
]{advancedproof}

\begin{document}

\begin{advanced}
Inside advanced environment.
\begin{advancedproof}
inside proof
\end{advancedproof}
\end{advanced}


\begin{advanced}
Inside advanced environment. But without any other internal environment
\end{advanced}

\end{document}

答案1

您可以用以下内容替换您的代码。这只是转换\\\vspace*{0pt}

\documentclass{article}

\usepackage{amsmath,amsfonts,amssymb,amsthm} % For math equations, theorems, symbols, etc
\usepackage{thmtools}

\newif\ifadvanced % advanced environment
\advancedtrue % comment out to hide advanced environments


\newcommand{\separator}{\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}}
\newenvironment{advanced}{\ifadvanced\par\separator \small \fi}{\ifadvanced\vspace*{0pt}\separator\par\fi}

\declaretheoremstyle[%
  spaceabove=-6pt,%
  spacebelow=6pt,%
  headfont=\normalfont\itshape,%
  postheadspace=1em,%
  qed=\qedsymbol%
]{myproofstyle} 
\declaretheorem[name={Proof},style=myproofstyle,unnumbered,
]{advancedproof}

\begin{document}

\begin{advanced}
Inside advanced environment.
\begin{advancedproof}
inside proof
\end{advancedproof}
\end{advanced}
\end{document}

更新:您的问题应该使用

\newenvironment{advanced}{\ifadvanced\par\separator \small \fi}{\ifadvanced\vspace*{-.75em}\par\separator\par\fi}

相关内容