I am in the process of finalizing the notebook text, and I am into framing equations and figures. For this I am testing mdframed
package, which produces nice frames. However, I don't know how to frame only equations, without framing equation numbers. Is that possible in mdframed
?
[Tex/LaTex] Putting frame only around equation using mdframed package
mdframed
Related Solutions
The problem occurs that the the background is drawn without any rounded corners if you set the option topline=true
. However you can hack the test:
\makeatletter
\let\mdf@putbox@single@orig\mdf@putbox@single
\mdfapptodefinestyle{definition}{%
settings={%
\def\mdf@putbox@single{%
\let\mdf@test@t\@gobbletwo
\let\mdf@test@noline\@firstoftwo
\mdf@putbox@single@orig
}%
}%
}
\makeatother
After the hack you must expand the option singlextra
by the following line:
\path[draw=white,line width=1.7em,overlay] (O|-P) -- (P);
to draw a white background of your title.
The odd corner of the second page a can't reproduce.
Here the output:
Here the complete code:
\documentclass{scrartcl}
\usepackage{times}
\usepackage{lipsum}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,shadows}
\usepackage[framemethod=tikz]{mdframed}
\tikzset{
title/.style={
fill=white,
font=\normalfont,
text=black,
anchor=base west,
},
contour/.style = {
line width = 0.6pt,
draw = black,
rounded corners = 2ex,
},
fakeshadow/.style = {
line width = 4.5pt,
draw = white,
},
}
\newcommand{\definitiontitle}{
{\scshape \bfseries \Large Definition}
}
\mdfdefinestyle{definition}{%
singleextra={%
%% Store (O) in \p1, store (P) in \p2. Now \p1=(\x1,\y1) and \p2=(\x2,\y2). From that, define (Q) = (\x1,\y2).
\path let \p1=(O), \p2=(P) in (\x1,\y2) coordinate (Q);
\path let \p1=(O), \p2=(P) in (\x2,\y1) coordinate (R);
\path let \p1=(O), \p2=(Q) in (\x1,{(\y1+\y2)/2}) coordinate (M);
\path[draw=white,line width=1.7em,overlay] (O|-P) -- (P);
\path[contour,] (M) |- (P) |- (O) -- (M);
\node[title, anchor=west, xshift=18pt - 5pt] at (Q) {\definitiontitle};
},
firstextra={%
\path let \p1=(O), \p2=(P) in (\x1,\y2) coordinate (Q);
\path let \p1=(O), \p2=(P) in (\x2,\y1) coordinate (R);
\path[contour] (O) -- (Q) -- (P) -- (R);
\node[title, anchor=west, xshift=18pt - 5pt] at (Q) {\definitiontitle};
\path[fakeshadow] ($(O)+(1pt,-1.5pt)$) -- ($(R)+(-1pt,-1.5pt)$); %% Hide the bottom shadow
},
secondextra={%
\path let \p1=(O), \p2=(P) in (\x1,\y2) coordinate (Q);
\path let \p1=(O), \p2=(P) in (\x2,\y1) coordinate (R);
\path[contour] (Q) -- (O) -- (R) -- (P);
},
middleextra={%
\path let \p1=(O), \p2=(P) in (\x1,\y2) coordinate (Q);
\path let \p1=(O), \p2=(P) in (\x2,\y1) coordinate (R);
\path[contour] (O) -- (Q);
\path[contour] (P) -- (R);
\path[fakeshadow] ($(O)+(1pt,-1.5pt)$) -- ($(R)+(-1pt,-1.5pt)$); %% Hide the bottom shadow
},
align=center,
backgroundcolor=yellow,
userdefinedwidth=.9\textwidth,
middlelinewidth=1.7em,middlelinecolor=white,
hidealllines=true,topline=true,
innertopmargin=6pt,
innerbottommargin=18pt,
innerleftmargin=18pt,
innerrightmargin=18pt,
splitbottomskip=8pt,
splittopskip=16pt,
roundcorner=2ex,
% shadow=true,
shadowsize=5,
shadowcolor=black!40,
%% Experimental
needspace=3em,
ignorelastdescenders=true,
}
\makeatletter
\let\mdf@putbox@single@orig\mdf@putbox@single
\mdfapptodefinestyle{definition}{%
settings={%
\def\mdf@putbox@single{%
\let\mdf@test@t\@gobbletwo
\let\mdf@test@noline\@firstoftwo
\mdf@putbox@single@orig
}%
}%
}
\makeatother
\begin{document}
\lipsum[3]
\vspace{1\baselineskip}
\begin{mdframed}[style=definition]
\lipsum[1]
\end{mdframed}
\vspace{1\baselineskip}
\lipsum[3]
\vspace{1\baselineskip}
\begin{mdframed}[style=definition]
\lipsum[1-2]
\end{mdframed}
\vspace{1\baselineskip}
\lipsum[3]
\vspace{1\baselineskip}
\begin{mdframed}[style=definition]
\lipsum[1-8]
\end{mdframed}
\end{document}
tcolorbox
is more advanced and fancier for such jobs. Here is a simple example to get you started.
\documentclass[12pt,a4paper]{article}
\usepackage{kantlipsum}
\usepackage{tcolorbox}%
\tcbuselibrary{breakable}
\begin{document}%
\begin{tcolorbox}[boxrule=1pt,colback=yellow!30,arc=0mm, breakable] %% you can add many more options if
%% you like.
\section{Some section}
\kant[1-5]
\subsection{A subsection}
\kant[1]
\end{tcolorbox}
\end{document}
You can make it fancier and adjust dimensions etc. For details refer to the manual.
Best Answer
To supplement the answer of Harish Kumar, the packages
empheq
andtcolorbox
can by used in symbiosis.empheq
allows to specify any box to mark the given equations. For the box you may insert anytcolorbox
which behaves likefbox
. Typically, such boxes are based on the\tcbox
macro (like\tcbhighmath
in the answer of Harish Kumar).I think, the following example demonstrates what you can do. The singleline equation is boxed with
\tcbhighmath
directly, the multiline equations (align
) are boxed usingempheq
in conjunction with\tcbhighmath
and some other\tcbox
-based examples.