I'd like to wrap the proof
environment to add bars on the left (the \tcolorbox
package does not handle foot notes properly). However, when I do the wrapping I get unwanted space before and after the proof:
while tcolorbox
does the wrapping correctly (except that it does not handle footnotes properly):
What is the proper way to remove the space before and after the environment proof, and add it back before/after my wrapping?
MWE
\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}
UPDATE
To answer to egreg, I may not have been clear enough, but I don't want to use anymore tcolorbox
(because it poorly handles footnotes), I just want to fake it. So here is a new MWE that does not use tcolorbox at all. For now I can fake the desired look using [yshift=-2.5mm]
:
If I don't use this shift, I get a line which is too high (it starts before the space instead of after), which I don't want:
However, hardcoding the shift gives bad results if the text has some height (the top of the box is not aligned anymore with the line), and I expect other breakages, for instance if the space at the top of a page is not the same…
That's why I'm wondering if there is a generic way to move space from before the function to after. I tried the solution of egreg, but it seems that the space is added inside \trivlist
, so this does not solve my problem. Ideally, I'd like the solution to work for any environment: \tcolorbox
seems to be able to wrap any environment so I guess there should be a way to do that.
\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}
UPDATE
Thanks a lot for your answer egreg, but as far as I see this still does not handle properly the height of the line: the height is not the one of the text but of the "proof" text in your example.
My above example was actually closer to what I wanted, it's just that if you look carefully you'll see that the top part of the rule is not exactly aligned with the line on the left (it's a bit above it). Ok, I'm maybe a bit nit-picking, but I was more generally curious to know if there are general methods to remove the space of an environment without manually copy/pasting this environment and removing the space where it appears (tcolorbox seems to have an automatic procedure to do that, I don't think it has a different specification for each environment).
UPDATE
The above solution was not always working, for instance here is an issue with theorems:
\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}
However I read here Why does a parbox of height zero consume vertical space? that \nointerlineskip
could help to remove spacing. And I tried to put \nointerlineskip
at two positions, and indeed it helps, but we still need to modify baselineskip and friends.
Not sure if it's the proper way to remove space, nor how resilient it is, or if there are more proper solutions, so far it looks a bit like cooking...
% 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}
EDIT
Also, note that there is a function \removelastskip
to... remove the last space as explained here.
\end{proof}
before the\tikzmark
which makes it harder to ensure good positioning of the mark. You have%
all over the code but most of them are following command names so do nothing, and ones after length literals like0pt
shouldn't be there but despite all the%
elsewhere\end{proof} \nobreak} %
has two explicit spaces added,\begin{adjustwidth}{0mm}{0mm}
around my code actually removes the space (i.e. when I remove this line, I have more space). Any idea what black magic is involved?\addZeroWidthLine
for example could simply use a group rather than restoring everything (and you seem to have omitted\parskip
), but it is making a paragraph so making getting the spacing right harder, you could add the tikzmark in vertical mode without generating a paragraph or better add the marks in the existing paragraph so they don't add extra vertical material.