15

You can use soul: \documentclass[a4paper]{article} \usepackage{soul} \usepackage{xcolor} \newcommand{\ctext}[3][RGB]{% \begingroup \definecolor{hlcolor}{#1}{#2}\sethlcolor{hlcolor}% \hl{#3}% \endgroup } \begin{document} \noindent \ctext[RGB]{0,209,0}{This block represents a generic three phase back emf, like a power line, as vectors.} \\ \ctext[...


14

Is this what you intended? \documentclass{article} \usepackage{xcolor} \usepackage{soul} \newcommand{\mathcolorbox}[2]{\colorbox{#1}{$\displaystyle #2$}} \begin{document} For inline math, one can simply do \hl{colored $a=b$ math}. For display math, the following works: \begin{equation} \mathcolorbox{red}{y=\frac{x^2}{q}}+z \end{equation} \end{document} ...


10

It was fun :) You asked two questions, so there are two answers: The first one is the box. I copied the definition of xcolor's \colorbox, modified it, and called it \tallcbox. The difference is that the size of the \colorbox is the size of its contents plus \fboxsep to each side. I changed \tallcbox to have the same width as the contents, and have ...


7

EDITED to turn it into a macro. Took Dai's suggestion to add a \strut, to account for squat equations. \documentclass{article} \usepackage{xcolor,stackengine} \newcommand\redbox[1]{% \fboxsep=-2pt \def\tmp{\displaystyle\strut #1} \def\shadow{\makebox[.4pt]{$\tmp$}} \stackengine{0pt}{% \stackengine{0pt}{% \textcolor{red}{\fbox{~~$\phantom{\...


6

May be better a custom tcolorbox than a tabular environment? Note that you can change the exact place of "Key Points" with the yshift and xshift options. \documentclass[12pt]{article} \usepackage[many]{tcolorbox} \usepackage[utf8]{inputenc} \newcommand{\zx}[1]{\textcolor{blue!85!red}{\emph{#1}}} \newtcolorbox{mybox}[2][]{boxsep=1em,left=-1em, colback=blue!...


6

Here you have an example with tcolorbox. Colors and margins can be easily adapted. \documentclass{article} \usepackage[most]{tcolorbox} \newtcolorbox{myquote}[1][]{% colback=black!5, colframe=black!5, notitle, sharp corners, borderline west={2pt}{0pt}{red!80!black}, enhanced, breakable, } \usepackage{lipsum} \begin{...


6

(works for non numbered only) You can apply the color to the whole environment simply using \color{} before it. But, make sure that the color changes apply only to the environment, so embrace everything with braces, that is, {\color{<color>}...} Off topic: I would not use those \left \right. MWE \documentclass{article} \usepackage[svgnames,...


6

A small variation of Sigur's answer: I define an environment instead of a macro (my idiosyncrasy: I find it better to read) and declare a new tag form which guarantees that the equation number is still printed in black. \documentclass{article} \usepackage[svgnames, x11names]{xcolor} \usepackage{empheq} % provided by mathtools, which is loaded by empheq \...


6

tcolorbox is arguably one of the most powerful option if you seek extensions later on. \documentclass{article} \usepackage{tcolorbox} \tcbuselibrary{skins} \usetikzlibrary{calc} \tcbset{twilight/.style={enhanced,hbox,colback=white, underlay={\begin{tcbclipinterior} \fill[#1] let \p1=($(interior.north)-(interior.south)$) in ([yshift={0.5*\y1}]interior.south ...


5

I suggest to use enumitem packages and with it make itemize list in your table. Also all complication with colored box is better to replace with simple table cell colored by \cellcolor{<color}{<cell content>}: \documentclass[french]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{babel} \usepackage[table,dvipsnames]{xcolor}...


5

You can set \fboxsep to 0pt and then increase the height of the material inside manually if you need. \documentclass{article} \usepackage{xcolor} \setlength{\fboxsep}{0pt} \begin{document} \colorbox{black!15}{[\textsubscript{CP} laa3 [\textsubscript{TP} \textit{t} zau2-zo2]\strut}] \bigskip \colorbox{black!15}{[\textsubscript{CP} laa3 [\textsubscript{TP} \...


4

Here's a solution which places a framebox only around the itemized items; that way, I believe, the "Key Points" header rectangle is actually given more, rather than less, visual prominence. \documentclass[french]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{babel} \usepackage[dvipsnames,table]{xcolor} \usepackage[colorlinks,...


4

tcolorbox can be your new friend: \documentclass{article} \usepackage{xcolor} \usepackage{tcolorbox} \begin{document} \begin{tcolorbox}[ sharp corners, rounded corners=northeast, colback=green!35!brown, colframe=green!35!brown, arc=5mm, text width=.85cm ] \color{white}Test \end{tcolorbox} \end{document}


4

You could redefine \colorbox: \renewcommand<>\colorbox[2]{\only#3{\beameroriginal\colorbox{#1}{#2}}} But maybe it is better to define a new command: \newcommand<>\hlbox[2]{\only#3{\colorbox{#1}{#2}}} Example \documentclass{beamer} \newcommand<>\hlbox[2]{\only#3{\colorbox{#1}{#2}}} \begin{document} \begin{frame} \centering \hlbox<1&...


4

Two variants: \documentclass[a4paper, 12pt, DIV10]{article} \usepackage[ngerman]{babel} \usepackage{xcolor} \usepackage[explicit]{titlesec} \usepackage{lipsum} \usepackage{tikz} \titleformat{\subsubsection} {\normalfont\Large\bfseries} {} {0em} {\pgfsetfillopacity{0.5}\colorbox{orange}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{blue}{\...


4

A simple tabular with coloured columns will do: \documentclass[a4paper]{article}%{scrartcl} \usepackage[english]{babel} \usepackage[utf8]{inputenc} \usepackage{fancyhdr} \usepackage{array} \usepackage{graphicx} \usepackage{sectsty} \usepackage[table]{xcolor} \definecolor{darkblue}{HTML}{00008A} \definecolor{lightblue}{HTML}{C8C8FA} \sectionfont{\color{...


4

Here's a conceptually different version using xsim and tcolorbox. \documentclass{book} \title{Introduction to Latex} \author{Me} \date{} \usepackage{xsim} \usepackage[skins]{tcolorbox} \xsimsetup{solution/print=false} \DeclareExerciseEnvironmentTemplate{tcolorbox}{% \tcolorbox[enhanced,left=2pt,right=2pt,title=\GetExerciseName~\thesubsection,% append .\...


4

You have to move the box left by \oddsidemargin+1in, besides taking into account \fboxsep. \documentclass[letterpaper, 12pt]{scrartcl} \usepackage{color} \usepackage{lipsum} \begin{document} \noindent\makebox[\textwidth][l]{% \hspace{-\dimexpr\oddsidemargin+1in}% \colorbox{cyan}{% \parbox{\dimexpr\paperwidth-2\fboxsep}{\lipsum[3]}% }% } \end{...


4

You could use a simple tcolorbox. Of course, you will use your image instead of example-image-a. \documentclass{article} \usepackage{tikz,lipsum,lmodern} \usepackage[most]{tcolorbox} \usepackage{tabularx} \usepackage{graphbox} \begin{document} \begin{tcolorbox}[colback=lightgray!40,colframe=lightgray] \begin{verbatim} library("Tidyverse") library("Quandl")...


4

The argument to \colorbox “forgets” being called in smaller size. You need \mathpalette. \documentclass{article} \usepackage{xcolor} \usepackage{mathtools} \makeatletter \newcommand{\colormathbox}[3][\mathord]{% #1{% \setlength{\fboxsep}{1pt}% \mathpalette\color@mathbox{{#2}{#3}}% }% } \newcommand{\color@mathbox}[2]{% \color@@mathbox#1#2% } \...


4

Use comment at end of line % and give \setlength{\fboxsep}{0pt} \documentclass[parskip]{scrbook} \usepackage{xcolor} \setlength{\fboxsep}{0pt} \begin{document} \texttt{AjuC ER7 (R) (24) E% \color{white}\colorbox{black}{VRAAGLNF}% \color{black}L% \color{white}\colorbox{black}{DVL}% \color{black}S% \color{...


4

I'm almost re-taking the answer by @Mu30 murugans2katgmail and adding the vertical padding with the strut trick (here created with an invisible rule): \documentclass[parskip]{scrbook} \usepackage{xcolor} \setlength{\fboxsep}{0pt} \let\oldcolbox\colorbox \renewcommand\colorbox[2]{% \oldcolbox{#1}{\rule[-.5ex]{0pt}{2.5ex}#2}% }% \begin{document} ...


4

You can have a syntax that allows to align the letters in the source: !c{...} denotes a colored block, where c is either b, g or r ~ means a “real space” spaces are ignored and can be used for aligning the characters in the source. Here's the code: \documentclass{article} \usepackage{xcolor} \newenvironment{basseur} {% \makeactives \fboxsep=0pt \...


4

The following solution shows two approaches: (1) use \colorbox and reduce the spacing at all sides and (2) use \tcbox from tcolorbox and change the sides independently. \documentclass[a4paper, 12pt]{article} \renewcommand{\rmdefault}{ptm} \usepackage[table]{xcolor} \definecolor{tpgray}{gray}{0.90} \newcommand{\tp}[1]{\colorbox{tpgray}{#1}} \setlength{\...


4

your problem is solved by koleygr's comment, so i add some off-topic suggestion for your code: \documentclass{article} \usepackage{amsmath,xcolor} \begin{document} \[ \setlength{\fboxsep}{1.5pt} \begin{tabular}{c|c} \hline \textbf{Factors of \textcolor{blue}{6}} & \textbf{Sum of Factors} \\ \hline 1,6 & ...


Only top voted, non community-wiki answers of a minimum length are eligible