How I can highlight equation as given below:
[Tex/LaTex] How to highlight equations in mathematics
highlighting
Related Solutions
You could use TikZ, and
- the
fit
library for creating nodes fitting the desired area, - a style for the highlighted node, so separated from the code and easy to change,
- the TikZ options
overlay
andremember picture
, so you can later refer to those nodes, for example for drawing arrows and annotations later.
To demonstrate why it's useful to have nodes for reference, I created an example, which shows transposing a matrix, highlights a submatrix both in the original matrix and the result, connected by an arrow and annotated:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\tikzset{%
highlight/.style={rectangle,rounded corners,fill=red!15,draw,
fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
\tikz[overlay,remember picture]{
\node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\begin{document}
\[
M = \left(\begin{array}{*5{c}}
\tikzmark{left}{1} & 2 & 3 & 4 & 5 \\
6 & 7 & 8 & 9 & 10 \\
11 & 12 & \tikzmark{right}{13} & 14 & 15 \\
16 & 17 & 18 & 19 & 20
\end{array}\right)
\Highlight[first]
\qquad
M^T = \left(\begin{array}{*5{c}}
\tikzmark{left}{1} & 6 & 11 & 16 \\
2 & 7 & 12 & 17 \\
3 & 8 & \tikzmark{right}{13} & 18 \\
4 & 9 & 14 & 19 \\
5 & 10 & 15 & 20
\end{array}\right)
\]
\Highlight[second]
%
\tikz[overlay,remember picture] {
\draw[->,thick,red,dashed] (first) -- (second) node [pos=0.66,above] {Transpose};
\node[above of=first] {$N$};
\node[above of=second] {$N^T$};
}
\end{document}
You can use the bclogo
and/or mdframed
and or tcolorbox
packages.
The main difference is that boxes produced using mdframed
or tcolorbox
might allow page breaks.
A little example; the first box was produced using bclogo
; the second one, using mdframed
; the third one (similar to the second one) and the fourth one were produced using tcolorbox
:
\documentclass{book}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\definecolor{bgblue}{RGB}{245,243,253}
\definecolor{ttblue}{RGB}{91,194,224}
\mdfdefinestyle{mystyle}{%
rightline=true,
innerleftmargin=10,
innerrightmargin=10,
outerlinewidth=3pt,
topline=false,
rightline=true,
bottomline=false,
skipabove=\topsep,
skipbelow=\topsep
}
\newtcolorbox{myboxi}[1][]{
breakable,
title=#1,
colback=white,
colbacktitle=white,
coltitle=black,
fonttitle=\bfseries,
bottomrule=0pt,
toprule=0pt,
leftrule=3pt,
rightrule=3pt,
titlerule=0pt,
arc=0pt,
outer arc=0pt,
colframe=black,
}
\newtcolorbox{myboxii}[1][]{
breakable,
freelance,
title=#1,
colback=white,
colbacktitle=white,
coltitle=black,
fonttitle=\bfseries,
bottomrule=0pt,
boxrule=0pt,
colframe=white,
overlay unbroken and first={
\draw[red!75!black,line width=3pt]
([xshift=5pt]frame.north west) --
(frame.north west) --
(frame.south west);
\draw[red!75!black,line width=3pt]
([xshift=-5pt]frame.north east) --
(frame.north east) --
(frame.south east);
},
overlay unbroken app={
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south west) --
([xshift=5pt]frame.south west);
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south east) --
([xshift=-5pt]frame.south east);
},
overlay middle and last={
\draw[red!75!black,line width=3pt]
(frame.north west) --
(frame.south west);
\draw[red!75!black,line width=3pt]
(frame.north east) --
(frame.south east);
},
overlay last app={
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south west) --
([xshift=5pt]frame.south west);
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south east) --
([xshift=-5pt]frame.south east);
},
}
\begin{document}
\renewcommand\bcStyleTitre[1]{\large\textcolor{ttblue}{#1}}
\begin{bclogo}[
couleur=bgblue,
arrondi=0,
logo=\bcbombe,
barre=none,
noborder=true]{Commom Programming Error}
\itshape\lipsum[4]
\end{bclogo}
\begin{mdframed}[style=mystyle,frametitle=Web addresses in text]
\lipsum[4]
\end{mdframed}
\begin{myboxi}[Web addresses in text]
\lipsum[4]
\end{myboxi}
\begin{myboxii}[Web addresses in text]
\lipsum[4]
\end{myboxii}
\end{document}
The packages offer you many customization possibilities and the documentations contain numerous examples.
For the second framed box, here's another option using TikZ
:
\documentclass{book}
\usepackage{environ}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}
\NewEnviron{myremark}[1]
{\par\medskip\noindent
\begin{tikzpicture}
\node[inner sep=0pt] (box) {\parbox[t]{.99\textwidth}{%
\begin{minipage}{.3\textwidth}
\centering\tikz[scale=5]\node[scale=3,rotate=30]{\bclampe};
\end{minipage}%
\begin{minipage}{.65\textwidth}
\textbf{#1}\par\smallskip
\BODY
\end{minipage}\hfill}%
};
\draw[red!75!black,line width=3pt]
( $ (box.north east) + (-5pt,3pt) $ ) -- ( $ (box.north east) + (0,3pt) $ ) -- ( $ (box.south east) + (0,-3pt) $ ) -- + (-5pt,0);
\draw[red!75!black,line width=3pt]
( $ (box.north west) + (5pt,3pt) $ ) -- ( $ (box.north west) + (0,3pt) $ ) -- ( $ (box.south west) + (0,-3pt) $ ) -- + (5pt,0);
\end{tikzpicture}\par\medskip%
}
\begin{document}
\lipsum[4]
\begin{myremark}{Web addresses in texts}
\lipsum[4]
\end{myremark}
\lipsum[4]
\end{document}
Best Answer
You can play around with the spacing:
Ultimately you can just use
\colorbox{<color>}{<stuff>}
to highlight content. I've added\strut
to ensure a consistent baseline height of the resulting coloured box, as well as using text where it seemed necessary. Note that<stuff>
inside a\colorbox
is set in text mode.