删除证明环境前后的空格

删除证明环境前后的空格

我想包装proof环境以在左侧添加条形图(该\tcolorbox包无法正确处理脚注)。但是,当我进行包装时,我在证明前后得到了不需要的空间:

在此处输入图片描述

虽然tcolorbox可以正确进行换行(但不能正确处理脚注):

在此处输入图片描述

删除环境证明前后的空间并在包装之前/之后将其添加回去的正确方法是什么?

平均能量损失

\documentclass{article}
\RequirePackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{changepage}
% To show that tcolorbox has no troubles to wrap:
\RequirePackage[many]{tcolorbox}
\newenvironment{prooftcolor}{\begin{proof}}{\end{proof}}
\tcolorboxenvironment{prooftcolor}{
  blanker,
  before skip=\topsep,
  after skip=\topsep,
  borderline west={0.4pt}{0.4pt}{black},
  breakable,
  left=2.5mm,
  grow to left by=2.5mm,
}
\usepackage{hyperref}
\usepackage{lipsum}
\begin{document}

\section{Version adjustwidth}
\lipsum[1]

\newlength{\oldbaselineskip}
\newlength{\oldlineskip}
\newlength{\oldlineskiplimit}

\long\def\addZeroWidthLine#1{%
  \oldbaselineskip=\baselineskip%
  \oldlineskip=\lineskip%
  \oldlineskiplimit=\lineskiplimit%
  \baselineskip=0pt%
  \lineskip=0pt%
  \lineskiplimit=0pt%
  \noindent#1\par\nobreak%
  \baselineskip=\oldbaselineskip%
  \lineskip=\oldlineskip%
  \lineskiplimit=\oldlineskiplimit%
}


\begin{adjustwidth}{0mm}{0mm}
  \addZeroWidthLine{\tikzmark{A}}%
  {\begin{proof}
    Hello
  \end{proof} \nobreak} % nobreak is used to avoid a new page between proof and tikzmark.
  \addZeroWidthLine{\tikzmark{B}}
\end{adjustwidth}
\tikz[remember picture, overlay] \draw (pic cs:A) -- (pic cs:B);


\section{Version tcolorbox}

\begin{prooftcolor}%
  Hello\footnote{Hello.}
  Blablabla.
\end{prooftcolor}


\end{document}

更新

回答 egreg,我可能说得不够清楚,但我不想再使用了tcolorbox(因为它处理脚注很差),我只想伪造它。所以这里有一个根本不使用 tcolorbox 的新 MWE。现在我可以使用以下方法伪造所需的外观[yshift=-2.5mm]

在此处输入图片描述

如果我不使用这个转变,我会得到一条太高的线(它从空格之前而不是之后开始),这是我不想要的:

在此处输入图片描述

但是,如果文本有一定的高度(框的顶部不再与线对齐),则对移位进行硬编码会产生不好的结果,并且我预计还会出现其他中断,例如,如果页面顶部的空间不一样……

在此处输入图片描述

这就是为什么我想知道是否有一种通用的方法可以将空间从函数前移到函数后。我尝试了 egreg 的解决方案,但似乎空间是在里面添加的\trivlist,所以这不能解决我的问题。理想情况下,我希望该解决方案适用于任何环境:\tcolorbox似乎能够包装任何环境,所以我想应该有一种方法可以做到这一点。

\documentclass{article}
\RequirePackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{changepage}
\usepackage{lipsum}

\newlength{\oldbaselineskip}
\newlength{\oldlineskip}
\newlength{\oldlineskiplimit}

\long\def\addZeroWidthLine#1{%
  \oldbaselineskip=\baselineskip%
  \oldlineskip=\lineskip%
  \oldlineskiplimit=\lineskiplimit%
  \baselineskip=0pt%
  \lineskip=0pt%
  \lineskiplimit=0pt%
  \noindent#1\par\nobreak%
  \baselineskip=\oldbaselineskip%
  \lineskip=\oldlineskip%
  \lineskiplimit=\oldlineskiplimit%
}

\newenvironment{prooftest}{%
  \begin{adjustwidth}{-2.5mm}{0mm}%
    \addZeroWidthLine{\tikzmark{A}}% Adds a marker before the proof
    \begin{adjustwidth}{2.5mm}{0mm}%
      \begin{proof}%
  }{%
      \end{proof} % nobreak is used to avoid a new page between proof and tikzmark.
      \addZeroWidthLine{\tikzmark{B}\tikz[remember picture, overlay] \draw[line width=.2pt] ([yshift=-2.5mm]{pic cs:A}) -- ({pic cs:B}-|{pic cs:A});}%
    \end{adjustwidth}%
  \end{adjustwidth}
}


\begin{document}

\section{Version adjustwidth}
\lipsum[1]

\begin{prooftest} %
  Try %\rule[-5mm]{2cm}{2cm}
  to uncomment the rule to see how bad it is to hardcode values.
\end{prooftest}

\lipsum[1]

\end{document}

更新

非常感谢您的回答 egreg,但据我所知,这仍然不能正确处理行的高度:高度不是文本的高度,而是示例中“证明”文本的高度。

在此处输入图片描述

我上面的例子实际上更接近我想要的,只是如果你仔细看,你会发现规则的顶部与左边的线并不完全对齐(它稍微高一点)。好吧,我可能有点吹毛求疵,但我更想知道是否有通用方法可以删除环境的空间,而无需手动复制/粘贴此环境并删除它出现的空间(tcolorbox 似乎有一个自动程序来执行此操作,我认为它对每个环境没有不同的规范)。

更新

上述解决方案并不总是有效,例如这里有一个定理问题:

在此处输入图片描述

\documentclass{article}
\RequirePackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{changepage}
\usepackage{lipsum}
\usepackage{thmtools} %% Improves existing theorem packages (like amsthm) and provides declaretheorem
\theoremstyle{plain} % Style, see http://www.ams.org/arc/tex/amscls/amsthdoc.pdf p. 8 for recommanded styles
\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\newlength{\oldbaselineskip}
\newlength{\oldlineskip}
\newlength{\oldlineskiplimit}

%%% How to write properly this thing?
\long\def\addZeroWidthLine#1{%
  \oldbaselineskip=\baselineskip%
  \oldlineskip=\lineskip%
  \oldlineskiplimit=\lineskiplimit%
  \baselineskip=0pt%
  \lineskip=0pt%
  \lineskiplimit=0pt%
  \noindent#1\par\nobreak%
  \baselineskip=\oldbaselineskip%
  \lineskip=\oldlineskip%
  \lineskiplimit=\oldlineskiplimit%
}

\newenvironment{prooftest}{%
  \begin{adjustwidth}{-2.5mm}{0mm}%
    \addZeroWidthLine{\tikzmark{A}}% Adds a marker before the proof
    \begin{adjustwidth}{2.5mm}{0mm}%
      \begin{proof}%
  }{%
      \end{proof} % nobreak is used to avoid a new page between proof and tikzmark.
      \addZeroWidthLine{\tikzmark{B}\tikz[remember picture, overlay] \draw[line width=.2pt] ([yshift=-2.5mm]{pic cs:A}) -- ({pic cs:B}-|{pic cs:A});}%
    \end{adjustwidth}%
  \end{adjustwidth}
}


\begin{document}

\section{Version adjustwidth}
\lipsum[1]

\begin{theorem}
  Hello
\end{theorem}

\begin{prooftest} %
  Try \rule[-5mm]{2cm}{2cm}
  to uncomment the rule to see how bad it is to hardcode values.
\end{prooftest}

\lipsum[1]

\end{document}

但是我在这里读到为什么高度为零的 parbox 会占用垂直空间?\nointerlineskip有助于消除间距。我尝试将其放在\nointerlineskip两个位置,确实有帮助,但我们仍需要修改 baselineskip 和相关元素。

在此处输入图片描述

不确定这是否是去除空间的正确方法,也不确定它的弹性如何,或者是否有更合适的解决方案,到目前为止它看起来有点像烹饪......

% https://tex.stackexchange.com/questions/532948/robustly-add-a-border-to-the-left-of-a-text-spanning-several-pages
\documentclass[a4paper,12pt]{memoir}
\usepackage{lipsum}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{thmtools} %% Improves existing theorem packages (like amsthm) and provides declaretheorem
\theoremstyle{plain} % Style, see http://www.ams.org/arc/tex/amscls/amsthdoc.pdf p. 8 for recommanded styles
\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\newlength{\oldbaselineskip}
\newlength{\oldlineskip}
\newlength{\oldlineskiplimit}

\long\def\addZeroWidthLine#1{%
  \nointerlineskip\oldbaselineskip=\baselineskip%
  \oldlineskip=\lineskip%
  \oldlineskiplimit=\lineskiplimit%
  \baselineskip=0pt%
  \lineskip=0pt%
  \lineskiplimit=0pt%
  \noindent#1\par\nointerlineskip\nobreak%
  \baselineskip=\oldbaselineskip%
  \lineskip=\oldlineskip%
  \lineskiplimit=\oldlineskiplimit%
}

\begin{document}

\newenvironment{prooftest}{%
  \begin{adjustwidth}{-2.5mm}{0mm}%
    \addZeroWidthLine{\tikzmark{A}}% Adds a marker before the proof
    \begin{adjustwidth}{2.5mm}{0mm}%
      \begin{proof}%
  }{%
      \end{proof} % nobreak is used to avoid a new page between proof and tikzmark.
      \addZeroWidthLine{\tikzmark{B}\tikz[remember picture, overlay] \draw[line width=.2pt] ([yshift=-2.5mm]{pic cs:A}) -- ({pic cs:B}-|{pic cs:A});}%
    \end{adjustwidth}%
  \end{adjustwidth}
}

\begin{theorem}
  See that this space is large:
\end{theorem}
\begin{prooftest}~% Use '~' to ensure  the subproof starts on a new line.
  % See also https://tex.stackexchange.com/questions/122954/starting-a-proof-with-paragraph
  % \begin{subproof}%
  We prove now that $1+1+1 = 3$. First we will prove that $1+1+1=3$:
\end{prooftest}


\begin{theorem}
  while this one is small:
\end{theorem}
\begin{proof}~% Use '~' to ensure  the subproof starts on a new line.
  % See also https://tex.stackexchange.com/questions/122954/starting-a-proof-with-paragraph
  % \begin{subproof}%
  We prove now that $1+1+1 = 3$. First we will prove that $1+1+1=3$:
\end{proof}

\end{document}

编辑

另请注意,有一个函数\removelastskip可以删除最后一个空格,如下所述这里

答案1

获取正确坐标的方法可能会得到改进。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{lipsum}

\newcounter{Proofcnt}
\newlength{\Proofht}
\newenvironment{Proof}
 {%
  \stepcounter{Proofcnt}%
  \begin{tikzproof}%
 }
 {%
  \end{tikzproof}%
 }

\newcommand{\tikzqed}{%
  \strut\openbox
  \tikzmark{B\theProofcnt}%
  \tikz[remember picture, overlay]
    \draw[line width=.2pt]
      ([xshift=-2.5mm,yshift=\Proofht]{pic cs:A\theProofcnt}) --
      ([xshift=-\the\dimexpr2.5mm+\linewidth]{pic cs:B\theProofcnt}-|{pic cs:A\theProofcnt});%
}
\makeatletter
\newenvironment{tikzproof}[1][\proofname]{\par
  \renewcommand{\qedsymbol}{\tikzqed}%
  \settoheight{\Proofht}{\proofname}%
  \pushQED{\qed}%
  \normalfont \topsep6\p@\@plus6\p@\relax%\z@skip
  \trivlist
  \item[\hskip\labelsep
        \itshape
    \tikzmark{A\theProofcnt}#1\@addpunct{.}]\ignorespaces
}{%
  \popQED\endtrivlist\@endpefalse
}
\makeatother

\begin{document}

\vspace*{\fill}

\section{No adjustwidth}

\lipsum[1][1-4]

\begin{Proof}
Test.\footnote{A note} \lipsum[2][1-4]
\end{Proof}

\lipsum[3][1-4]

\begin{Proof}
Test.\footnote{A note} \lipsum[2][1-4]
\[
a+b=c\qedhere
\]
\end{Proof}

\lipsum[3][1-4]

\end{document}

当然,如果校样中有分页符,则此方法无效。

在此处输入图片描述

相关内容