I am writing an Article in LaTeX.
Please suggest me how to create a highlight boxes like the ones shown below in LaTeX:
boxeshighlighting
I am writing an Article in LaTeX.
Please suggest me how to create a highlight boxes like the ones shown below in LaTeX:
Here's a list of other possible solutions
A solution that admits page breaks using mdframed
:
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
\lipsum[2]
\end{mdframed}
\lipsum[4]
\end{document}
The environments provided by the mdframed
package are highly customizable so, for example, using the (inner)leftmargin
, (inner)rightmargin
options, you can produce this (the textwidth remains unaltered and the frame extends a little into the margins):
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20,innerleftmargin=3pt,innerrightmargin=3pt,leftmargin=-3pt,rightmargin=-3pt]
\lipsum[2]
\end{mdframed}
\lipsum[4]
\end{document}
Here's now a solution using the framed
package and its shaded
environment; this solution also admits page breaks:
\documentclass{article}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{lipsum}
\colorlet{shadecolor}{blue!20}
\begin{document}
\lipsum[4]
\begin{shaded}
\lipsum[2]
\end{shaded}
\lipsum[4]
\end{document}
Now a solution using the tcolorbox
package; this solution admits page breaks inside tcolorbox
if you load the breakable
library and use the breakable
key:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
\begin{tcolorbox}[breakable,notitle,boxrule=0pt,colback=blue!20,colframe=blue!20]
\lipsum[2-20]
\end{tcolorbox}
\lipsum[4]
\end{document}
A solution using the adjustbox package (no page breaks allowed):
\documentclass{article}
\usepackage{xcolor}
\usepackage{adjustbox}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
\noindent\adjustbox{bgcolor=blue!20,minipage=[t]{\linewidth}}{\lipsum[4]}
\lipsum[4]
\end{document}
And finally, one solution using the fancypar
package (this solution won't accept page breaks either):
\documentclass{article}
\usepackage{fancypar}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
\ZebraPar[colorone=blue!20,colortwo=blue!20]{\lipsum[4]}
\lipsum[4]
\end{document}
Write after your given two lines to change the color of the leading box to white:
\definecolor{mycolor}{rgb}{255,255,255} % color white
\makeatletter % make @ a letter
\renewcommand*{\section}[1]{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#1}%
\parbox[t]{\hintscolumnwidth}{\strut\raggedleft\raisebox{\baseletterheight}{\color{mycolor}\rule{\hintscolumnwidth}{0.95ex}}}%
\hspace{\separatorcolumnwidth}%
\parbox[t]{\maincolumnwidth}{\strut\sectionstyle{#1}}%
\par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother
This workaround runs with the styles casual
and classic
but not with banking
.
I changed only the used color from \color{color1}
to \color{mycolor}
and set mycolor
to white
.
The original definition of macro section you can find in the file moderncvstyleclassic.sty
.
Have you checked the style banking
? This style does not use colored boxes.
moderncv
, version 2.0.0 (current version):with the current class moderncv
, version 2.0.0 the definition in style casual
has changed to:
\RenewDocumentCommand{\section}{sm}{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#2}%
\cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%
\par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
Therefore we need to use command \RenewDocumentCommand
to redefine \color{color1}
to \color{white}
. Please note that a patch with command \patchcmd
is not working, commands defined with \RenewDocumentCommand
are not patchable!
We need to add the following code into the preamble (\makeatletter
and \makeatother
are needed because the code uses @
):
\makeatletter
\RenewDocumentCommand{\section}{sm}{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#2}%
\cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{white}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%
\par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother
With the complete code
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual} % casual, classic, banking, oldstyle and fancy % head 2, body 1, foot 1
\moderncvcolor{black}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.75]{geometry}
\makeatletter
\RenewDocumentCommand{\section}{sm}{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#2}%
\cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{white}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%
\par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother
% personal data
\name{John}{Doe}
\title{Resumé title}
\address{street and number}{postcode city}{country}
\phone[mobile]{+1~(234)~567~890}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{john@doe.org}
\homepage{www.johndoe.com}
\social[linkedin]{john.doe}
\social[twitter]{jdoe}
\social[github]{jdoe}
\extrainfo{additional information}
\photo[64pt][0.4pt]{example-image-a}
\quote{Some quote}
\setlength{\footskip}{70pt}
\begin{document}
\makecvtitle
\section{Education}
\cventry{year--year}{Degree}{Institution--3}{City--4}{\textit{Grade}--5}{Description--6} % arguments 3 to 6 can be left empty
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}
\section{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}
\section{Experience}
\subsection{Vocational}
\cventry{year--year}{Job title}{Employer}{City}{}{General description
no longer than 1--2 lines.\newline{}%
Detailed achievements:%
\begin{itemize}%
\item Achievement 1;
\item Achievement 2, with sub-achievements:
\begin{itemize}%
\item Sub-achievement (a);
\item Sub-achievement (b), with sub-sub-achievements (don't do this!);
\begin{itemize}
\item Sub-sub-achievement i;
\item Sub-sub-achievement ii;
\item Sub-sub-achievement iii;
\end{itemize}
\item Sub-achievement (c);
\end{itemize}
\item Achievement 3.
\end{itemize}}
\cventry{year--year}{Job title}{Employer}{City}{}{Description
line 1\newline{}Description line 2}
\subsection{Miscellaneous}
\cventry{year--year}{Job title}{Employer}{City}{}{Description}
\end{document}
you get your wished result:
Best Answer
You can use the
bclogo
and/ormdframed
and ortcolorbox
packages.The main difference is that boxes produced using
mdframed
ortcolorbox
might allow page breaks.A little example; the first box was produced using
bclogo
; the second one, usingmdframed
; the third one (similar to the second one) and the fourth one were produced usingtcolorbox
:The packages offer you many customization possibilities and the documentations contain numerous examples.
For the second framed box, here's another option using
TikZ
: