# How to create Highlight Boxes in LaTeX?

I am writing an Article in LaTeX.

Please suggest me how to create a highlight boxes like the ones shown below in LaTeX:

• Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. – Leo Liu Aug 12 '12 at 2:23

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}

\lipsum[4]
\end{mdframed}

\lipsum[4]
\end{myboxi}

\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]
\lipsum[4]
\end{myremark}
\lipsum[4]

\end{document}


Here an example using mdframed whereby the symbols are taken from the package dingbat Instead of the symbols you can use every picture.

\documentclass{report}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{kantlipsum}

\usepackage{dingbat}%\eye and \leftpointright

\newcounter{error}[chapter]
\renewcommand*\theerror{\thechapter.\arabic{error}}
\tikzset{
errorsymbol/.style={%
rectangle,draw=blue,
,scale=2,overlay}}

\tikzset{
lampsymbol/.style={%
,scale=2,overlay}}

\newmdenv[hidealllines=true,backgroundcolor=blue!5,%
frametitle={\stepcounter{error}Comman~Programming~Error~\theerror},
frametitlefont=\color{blue!80!black}\bfseries,
skipabove=\topsep,skipbelow=\topsep,nobreak,
leftmargin=.3cm,rightmargin=.3cm, innerleftmargin=2cm,
singleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(2,\y1)$) node[errorsymbol] {\eye};},%
]{error}

\newmdenv[nobreak,middlelinewidth=.8pt,
frametitlefont=\bfseries,
leftmargin=.3cm,rightmargin=.3cm, innerleftmargin=2cm,
skipabove=\topsep,skipbelow=\topsep,
singleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(2,\y1)$) node[ lampsymbol] {\leftpointright};
\draw[line width=.8pt,white,] ($(O|-P)+(.2cm,0)$) -- ($(P)-(.2cm,0)$);
\draw[line width=.8pt,white,] ($(O)+(.2cm,0)$) -- ($(P|-O)-(.2cm,0)$);
},%
]{lamp}

\begin{document}
\begin{error}
Use only uppercase letters in the names of enumeration constants to make these
constants stand out in a program and to indicate that enumeration constants
are variables.
\end{error}

Use only uppercase letters in the names of enumeration constants to make these
constants stand out in a program and to indicate that enumeration constants
are variables.
\end{lamp}
\end{document}


It will most likely have to remain as a box that does not break across page boundaries. As such, a traditional "equation" with an image and a text box, all contained in a tabular should do:

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}
$\left[ \begin{tabular}{@{\quad}m{.3\textwidth}@{\qquad}m{.6\textwidth}@{\quad}} \includegraphics[width=\linewidth]{example-image-a} & \raggedright% \textbf{Web addresses in texts} \par There's a package called \texttt{url} designed for typesetting web addresses. Write \mbox{\texttt{\string\usepackage\string{url\string}}} in your preamble; this will provide the command \mbox{\texttt{\string\url}}. This command takes an address for the argument and will print it out with typewriter font. Furthermore, it is able to handle special characters in addresses like underscores and percent signs. It even enables hyphenation in addresses, which is useful for websites with a very long name.% \end{tabular} \right]$
\end{document}


awesomebox provides some default "highlight boxes", but this can be extended:

\documentclass{article}

\usepackage{awesomebox}
\usepackage[nopar]{lipsum}

\begin{document}

\lipsum[1]

\notebox{\lipsum[2]}

\tipbox{\lipsum[3]}

\warningbox{\lipsum[4]}

\cautionbox{\lipsum[5]}

\importantbox{\lipsum[6]}

\lipsum[7]

\end{document}

• Is it installed by default with texlive 2016, because I didn't found them in texlive 2015. – Sidahmed Feb 9 '17 at 17:22
• The package looks nice! However, it's worth noting that it requires using xelatex or luatex. – Czechnology May 25 '17 at 9:59
• Actually (2019) works also with pdflatex. – Fran Feb 25 at 10:24
1. My tipBox contains a lamb on the left that:
• can be colored or black and white
• can be vertically aligned in center or on top with the tip text through global document options.
2. It's width is adjustable for every use.
3. It will have a separator vertical line between the lamb and the text of the tip, and the width between the line and the lamb/text has to be equal and globally adjustable
4. It is inside a rectangle box and leave equal spaces above and left (from the lamb)/right (from the right edge of the text).

First edition

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{enumitem}

%Colors
\xdef\Colored{1}
\ifnum\Colored>0
\xdef\LWS{0.6mm}
\xdef\ColorYO{yellow!30!orange}
\xdef\ColorYR{yellow!70!red}
\xdef\ColorRY{red!90!yellow}
\xdef\ColorYB{yellow!90!brown}
\xdef\ColorYRB{yellow!90!red}
\xdef\ColorR{red}
\xdef\ColorO{orange}
\else
\xdef\LWS{0.4mm}
\xdef\ColorYO{gray!80!black}
\xdef\ColorYR{gray!70}
\xdef\ColorRY{gray!60!black}
\xdef\ColorYB{gray!90}
\xdef\ColorYRB{gray!50}
\xdef\ColorR{black}
\xdef\ColorO{gray!95!black}
\fi

%For the tip box
\newenvironment{enuma}{\begin{enumerate}[label={\alph{enumi})},itemsep=-1mm]}{\end{enumerate}}
\newlength\tipWidth
\setlength\tipWidth{\textwidth}
\newlength\tipSeparator
\newlength\tipTextWidth
\newlength\RectHeight
\setlength\tipSeparator{6mm}
\newsavebox{\lambBox}
\newsavebox{\lambVBox}
\newsavebox{\tipBox}
\newsavebox{\tipVBox}
\newcommand{\myTip}[3][\tipWidth]{%
\def\alig{#2}%
\def\aligm{m}%
\def\aligt{t}%
\savebox{\lambBox}{\hbox{\begin{tikzpicture}[inner sep=0,outer sep=0]
\fill[rounded corners=0.35mm,rotate=-15,gray!90!black] (0.05,-0.15)rectangle(-0.1,-0.02);
\draw[line width=0.9mm] (0.2,0.01) to[in=330 , out=170] (-0.2,0.11);
\draw[line width=1mm] (0.3,0.15) to[in=330 , out=170] (-0.25,0.25);
\draw[line width=1.1mm] (0.35,0.3) to[in=350 , out=180] (-0.27,0.36);
\draw[line width=\LWS, color=\ColorYO] (-0.15,0.42) to[in=310,out=80] (-0.3,0.8)to[in=215,out=130](-0.37,1.15) to[out=45,in=150] (0.2,1.35)to[in=110,out=-30](0.56,0.99)to[in=45,out=290](0.41,0.69)to[in=80,out=215](0.2,0.37);
\draw[line width=0.2mm] (0.,0.33)--(-0.02,0.72);
\fill[\ColorYR] (-0.02,0.72)--(0.0,0.93)--(0.055,0.79)--(0.07,0.9)--(0.13,0.79)--(0.28,0.8)--(0.16,0.61)--(0.09,0.65)--(0.07,0.5)--(0.046,0.54)--cycle;
\fill[\ColorRY] (-0.02,0.72)--(0.008,0.78)--(0.05,0.68)--(0.07,0.84)--(0.15,0.74)--(0.28,0.8)--(0.165,0.69)--(0.10,0.74)--(0.07,0.63)--(0.045,0.63)--(0.015,0.72)--cycle;
y\draw[line width=0.2mm] (0.02,0.3)--(0.28,0.8);
\draw[line width=0.7mm,\ColorYB](0.25,1.46)--(0.32,1.69) (0.41,1.33)--(.61,1.57) (0.54,1.19)--(.7,1.33) (0.03,1.5)--(-0.0,1.8) (-0.18,1.42)--(-0.3,1.62) (-0.4,1.3)--(-0.58,1.49);
\draw[line width=0.3mm,\ColorYRB] (-0.3,1.05)to[in=120,out=20](0.5,0.96);
\end{tikzpicture}}}%
\savebox\lambVBox{\vbox{\usebox{\lambBox}}}%
\savebox{\tipBox}{\hbox{\begin{minipage}[inner sep=0,outer sep=0]{\tipTextWidth}{\noindent\bfseries TIP $\vert$} #3\end{minipage}}}%
\savebox{\tipVBox}{\vbox{\usebox{\tipBox}}}%
%
\begin{tikzpicture}[inner sep=0 outer sep -0]%
\node[inner sep=0,outer sep=0] at ({-0.5\wd\lambBox-0.5\tipSeparator},{\ifx\alig\aligm 0\else \ifdim\dimexpr\ht\tipVBox+\dp\tipVBox\relax > \dimexpr\ht\lambBox+\dp\lambBox\relax \dimexpr\ht\tipVBox-0.5\ht\lambBox\else 0\fi\fi}) {\usebox{\lambBox}};
\node[inner sep=0,outer sep =0] at ({0.5\tipTextWidth+0.5\tipSeparator},{\ifx\alig\aligm 0\else \ifdim\dimexpr\ht\tipVBox+\dp\tipVBox\relax > \dimexpr\ht\lambBox+\dp\lambBox\relax 0\else \dimexpr0.5\ht\lambBox-\ht\tipVBox\relax\fi\fi}) {\usebox{\tipBox}};
\draw[\ColorO,line width=0.5mm] (0,\ifdim\dimexpr\ht\tipVBox+\dp\tipVBox\relax > \dimexpr\ht\lambBox+\dp\lambBox\relax -\ht\tipVBox\else -0.5\ht\lambBox\fi)--(0,\ifdim\dimexpr\ht\tipVBox+\dp\tipVBox\relax > \dimexpr\ht\lambBox+\dp\lambBox\relax 0.5\ht\tipVBox+0.5\dp\tipVBox\else 0.5\ht\lambBox\fi);
\end{tikzpicture}%
}

\begin{document}

\noindent\myTip[0.875\textwidth]{t}{%
Here is a small tip
}

\lipsum[1]

\noindent\myTip[0.875\textwidth]{t}{%
Here is a tip with some items that will exceed the figure height.

PSs:

\begin{enuma}
\item I know there are much simpler ways like using anchors for the nodes
\item It supposed to be ane example for using and calculating dimensions to create something without calc'' or pgf'' packages
\item Sure it csan be written with better code but helps to understand dimansions
\end{enuma}
}

\end{document}


Second edition (no "dimexpr")

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{enumitem}
\xdef\Colored{1}
\ifnum\Colored > 0
\xdef\LWS{0.6mm}
\xdef\ColorYO{yellow!30!orange}
\xdef\ColorYR{yellow!70!red}
\xdef\ColorRY{red!90!yellow}
\xdef\ColorYB{yellow!90!brown}
\xdef\ColorYRB{yellow!90!red}
\xdef\ColorR{red}
\xdef\ColorO{orange}
\else
\xdef\LWS{0.4mm}
\xdef\ColorYO{gray!80!black}
\xdef\ColorYR{gray!70}
\xdef\ColorRY{gray!60!black}
\xdef\ColorYB{gray!90}
\xdef\ColorYRB{gray!50}
\xdef\ColorR{black}
\xdef\ColorO{gray!95!black}
\fi
\newenvironment{enuma}{\begin{enumerate}[label={\alph{enumi})}, itemsep=-1mm]}{\end{enumerate}}
\newlength\tipWidth
\newlength\tipSeparator
\newlength\tipTextWidth
\newlength\RectHeight
\newlength\testL
\newlength\lengthA
\newlength\lengthB
\newlength\lengthC
\setlength\tipSeparator{6mm}
\newsavebox{\lambBox}
\newsavebox{\lambVBox}
\newsavebox{\tipBox}
\newsavebox{\tipVBox}
\newcommand{\myTip}[3][\tipWidth]{%
\def\alig{#2}%
\def\aligm{m}%
\def\aligt{t}%
\savebox{\lambBox}{\hbox{\begin{tikzpicture}[inner sep=0,outer sep=0]
\fill[rounded corners=0.35mm,rotate=-15,gray!90!black] (0.05,-0.15)rectangle(-0.1,-0.02);
\draw[line width=0.9mm] (0.2,0.01) to[in=330 , out=170] (-0.2,0.11);
\draw[line width=1mm] (0.3,0.15) to[in=330 , out=170] (-0.25,0.25);
\draw[line width=1.1mm] (0.35,0.3) to[in=350 , out=180] (-0.27,0.36);
\draw[line width=\LWS, color=\ColorYO] (-0.15,0.42) to[in=310,out=80] (-0.3,0.8)to[in=215,out=130](-0.37,1.15) to[out=45,in=150] (0.2,1.35)to[in=110,out=-30](0.56,0.99)to[in=45,out=290](0.41,0.69)to[in=80,out=215](0.2,0.37);
\draw[line width=0.2mm] (0.,0.33)--(-0.02,0.72);
\fill[\ColorYR] (-0.02,0.72)--(0.0,0.93)--(0.055,0.79)--(0.07,0.9)--(0.13,0.79)--(0.28,0.8)--(0.16,0.61)--(0.09,0.65)--(0.07,0.5)--(0.046,0.54)--cycle;
\fill[\ColorRY] (-0.02,0.72)--(0.008,0.78)--(0.05,0.68)--(0.07,0.84)--(0.15,0.74)--(0.28,0.8)--(0.165,0.69)--(0.10,0.74)--(0.07,0.63)--(0.045,0.63)--(0.015,0.72)--cycle;
\draw[line width=0.2mm] (0.02,0.3)--(0.28,0.8);
\draw[line width=0.7mm,\ColorYB](0.25,1.46)--(0.32,1.69) (0.41,1.33)--(.61,1.57) (0.54,1.19)--(.7,1.33) (0.03,1.5)--(-0.0,1.8) (-0.18,1.42)--(-0.3,1.62) (-0.4,1.3)--(-0.58,1.49);
\draw[line width=0.3mm,\ColorYRB] (-0.3,1.05)to[in=120,out=20](0.5,0.96);
\end{tikzpicture}}}%
\savebox\lambVBox{\vbox{\usebox{\lambBox}}}%
\setlength\tipTextWidth{0 pt}%
\savebox{\tipBox}{\hbox{\begin{minipage}[inner sep=0,outer sep=0]{\tipTextWidth}{\noindent\bfseries TIP $\vert$} #3\end{minipage}}}%
\savebox{\tipVBox}{\vbox{\usebox{\tipBox}}}%
\setlength\testL{\ht\tipVBox}%
\setlength\lengthA{\ht\tipVBox}%
\setlength\lengthB{0.5\ht\lambBox}%
\setlength\lengthC{0.5\ht\tipVBox}%
\begin{tikzpicture}[inner sep=0, outer sep =0]%
\node[inner sep=0,outer sep=0] at ({-0.5\wd\lambBox-0.5\tipSeparator},{\ifx\alig\aligm 0\else \ifdim\testL > 0pt \lengthA\else 0\fi\fi}) {\usebox{\lambBox}};
\node[inner sep=0,outer sep =0] at ({0.5\tipTextWidth+0.5\tipSeparator},{\ifx\alig\aligm 0\else \ifdim\testL > 0pt 0\else \lengthB\fi\fi}) {\usebox{\tipBox}};
\draw[\ColorO,line width=0.5mm] (0,\ifdim\testL> 0pt -\ht\tipVBox \else -0.5\ht\lambBox\fi)--(0,\ifdim\testL> 0pt \lengthC \else 0.5\ht\lambBox\fi);
\end{tikzpicture}%
}

\begin{document}

\noindent\myTip[0.875\textwidth]{t}{%
Here is a small tip
}

\lipsum[1]

\noindent\myTip[0.875\textwidth]{t}{%
Here is a tip with some items that will exceed the figure height.

PSs:

\begin{enuma}
\item I know there are much simpler ways like using anchors for the nodes
\item It supposed to be ane example for using and calculating dimensions to create something without calc'' or pgf'' packages
\item Sure it csan be written with better code but helps to understand dimansions
\item This second version doesn't use not even dimexpr'' and can work with wordpress quicklatex'' extension.
\end{enuma}
}
\end{document}

• I love your lamp and your box. Congratulations! Can you make the same box with the tcolorbox package? – AndréC Jul 27 at 10:48
• Thanks @AndréC ... I haven't use this package, I am trying to use as less packages as possible in order to gain a better understanding of LaTeX (and for many other reasons). – koleygr Jul 27 at 10:50
• I fully understand your point of view and I respect it. I'm trying to learn TeX, but it's very difficult. So, most of the time, I use packages. Concerning tcolorbox, its advantage is to be written with tikz-pgf (like your beautiful lamp) which allows an easy and fast adaptation of your code. In addition, the advantage of doing the same thing with tcolorbox is to allow ordinary users (like me) who have been using LaTeX for several years to configure this box more easily. For example, add a shadow, have square or round corners, etc. Translated with www.DeepL.com/Translator – AndréC Jul 27 at 10:58
• @AndréC ... Was the bounty from you? Thanks for your comment even if the bounty was from you even not ... I have no much time for answering questions now ... but when I develop something I think it should be shared ... I share that here ... Thanks again. – koleygr Aug 6 at 13:28
• Yes, your work is beautiful, i'm very happy to give you these bonus :) – AndréC Aug 6 at 14:58
\usepackage[most]{tcolorbox}

%textmarker style from colorbox doc
\tcbset{textmarker/.style={%
enhanced,
parbox=false,boxrule=0mm,boxsep=0mm,arc=0mm,
outer arc=0mm,left=6mm,right=3mm,top=7pt,bottom=7pt,
toptitle=1mm,bottomtitle=1mm,oversize}}

% define new colorboxes
\newtcolorbox{hintBox}{textmarker,
borderline west={6pt}{0pt}{yellow},
colback=yellow!10!white}
\newtcolorbox{importantBox}{textmarker,
borderline west={6pt}{0pt}{red},
colback=red!10!white}
\newtcolorbox{noteBox}{textmarker,
borderline west={6pt}{0pt}{green},
colback=green!10!white}

% define commands for easy access
\newcommand{\note}[1]{\begin{noteBox} \textbf{Note:} #1 \end{noteBox}}
\newcommand{\warning}[1]{\begin{hintBox} \textbf{Warning:} #1 \end{hintBox}}
\newcommand{\important}[1]{\begin{importantBox} \textbf{Important:} #1 \end{importantBox}}

\begin{document}

% draw some highlight boxes
\note{Certainly elsewhere my do allowance at. The address farther six hearted hundred towards husband. Strangers ye to he sometimes propriety in. She right plate seven has. Bed who perceive judgment did marianne.}
\warning{Doubtful two bed way pleasure confined followed. Shew up ye away no eyes life or were this.}
\important{Travelling alteration impression six all uncommonly. Chamber hearing inhabit joy highest private ask him our believe. Up nature valley do warmly. Entered of cordial do on no hearted.}

\end{document}



.

with the result:

• Hi, welcome, please make your code compileable. – AndréC Aug 11 at 16:06