Is it what you want ?
\documentclass{article}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{adjustbox}
\usepackage{tabu}
\begin{document}
\belowrulesep=0pt
\aboverulesep=0pt
\begin{center}
\begin{tabu}{X>{\columncolor{blue}}XXX}
1 & 2 & a & b\\
1 & 2 & a & b\\
\tabucline[green]-
1 & 2 & a & b\\
\arrayrulecolor{red}
\cmidrule(r{2.0ex}){1-2}\cmidrule(l{2.0ex}){3-4}
\adjustbox{margin=0pt 10pt 0pt 0pt}{1} & 2 & \cellcolor{green}a & b\\
\tabucline[blue]-
\adjustbox{margin=0pt 0pt 0pt 10pt}{1} & 2 & \cellcolor{green}a & b\\
\end{tabu}
\end{center}
\end{document}
This is more a hack than a real solution. I add margin inside the cells with adjustbox, and remove the space around cmidrule ....
Here's my version:
\documentclass{article}
\usepackage{mdframed,lipsum}
\parindent=0pt
\newmdenv[leftmargin=\dimexpr-0.5em-3pt, innerleftmargin=0.5em,
rightmargin=\dimexpr-0.5em-3pt, innerrightmargin=0.5em,
linewidth=3pt,linecolor=red, topline=false, bottomline=false,
innertopmargin=0pt,innerbottommargin=0pt,skipbelow=0pt,skipabove=0pt,
]{notex}
\newenvironment{note}
{\par\vskip\dimexpr\dp\strutbox-\prevdepth\relax\notex\strut\ignorespaces}
{\par\xdef\notetpd{\the\prevdepth}\endnotex\vskip-\notetpd\relax}
\begin{document}
\leavevmode\llap{\smash{\vrule depth7\baselineskip height0pt\hskip1em}}%
\lipsum*[2]
\begin{note}
\lipsum[2]
\end{note}
\leavevmode\llap{\smash{\vrule height\baselineskip\hskip1em}}%
\lipsum[2]
\end{document}
The black rules are just to show that the alignment is correct (they can't be too near the text because mdframed
applies a white background).
A magnified view of the top line
And one of the bottom line
At the start we ensure to skip by the glue TeX would insert and we add a strut to the first line in the note
environment, so to have the correct distance between baselines. At the end we do similarly, keeping into account the depth of the last line in the note
environment.
Brief explanation
mdframed
sets its chunks in a \vbox
which is inserted in the main vertical list; this usually upsets the interline spacing, as a \vbox
has its reference point at the baseline of the last box inside it. The package tries to do clever things not to add unwanted spaces, but in this case it's not sufficient.
So we need to emulate TeX's normal behavior. The distance from one baseline and the next is the sum of \dp\strutbox
and \ht\strutbox
; we can insert a strut in the first line of note
which makes it the correct height; but adding \dp\strutbox
vertical space will usually be too much, because the last line before note
may have descenders. So we end the paragraph so that \prevdepth
(an internal parameter) contains the depth of the last contributed box (precisely the last line). So we can add
\vskip\dp\strutbox-\prevdepth
and all is good. Something similar we have to do at the end. We end the paragraph and define \notetpd
to contain the value of \prevdepth
, so we can remove a vertical space with that amount, putting everything back in synch.
Best Answer
I looked at the definition of
\ev
in thephysics
package. In your case it essentially reduces toThe
\vphantom{\hat{O}_P}
will insert a box of zero width and of type mathord, but when followed by a mathopen atom (which\left
makes automatically), spacing is inserted.The definition of
\ev
makes absolutely no sense. The implementers are trying to reverse the effect of the automatic scaling of\left
and\right
by using\smash
to hide the height of the content, but then the construct will have no height and depth, so they reinserted using\vphantom
.The package code is also full of spurious spaces. Considering the quality of the implementation, the best way to fix this issue is by not using the
physics
package.