0

I would like my red box to be oval. Here is my code :

\documentclass[12pt,a4paper]{article}

\usepackage[latin1]{inputenc} 
\usepackage[T1]{fontenc}      
\usepackage[french]{babel}
\usepackage{amsmath,amssymb}
\usepackage{psfrag}
\usepackage{fancybox}
\usepackage{pgfplots}

\begin{document}

$$\ddot{x}+\colorbox{red!10}{$\frac{\omega_0}{Q}$}\dot{x}+\omega_0^2 x=0$$

\end{document}
5
  • Are you forced to use fancybox or do you accept solutions with other packages as well?
    – TeXnician
    Nov 26, 2017 at 12:32
  • 2
    Why not using tcolorbox?
    – user31729
    Nov 26, 2017 at 12:33
  • hi, I was having a look at this package documentation while you posted this. Right now, this is a bit too time consumming for what i wanna do. But will certainly use this package later to improve my handouts! Nov 26, 2017 at 12:40
  • 1
    @JeanLallemand: Time consuming? \tcbhighlight isn't really time - consuming. By the way,$$...$$ is deprecated for more than 20 years.
    – user31729
    Nov 26, 2017 at 12:50
  • Actually I meant \tcbhighmath
    – user31729
    Nov 26, 2017 at 16:41

2 Answers 2

1

Similar to Bernard's answer, with \tcboxmath from tcolorbox.

\documentclass[12pt,a4paper, french]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{amsmath,amssymb}
\usepackage[table]{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{%
  highlightstyle/.style={enhanced,colback=red!40,boxsep=0pt,frame hidden}
}


\begin{document}

\[ \ddot{x}+\tcboxmath[highlightstyle,sharp corners]{\frac{\omega_0}{Q}}\dot{x}+\omega_0^2 x=0 \]

\[ \ddot{x}+\tcboxmath[highlightstyle,auto outer arc, arc=15pt]{\frac{\omega_0}{Q}}\dot{x}+\omega_0^2 x=0 \]

\[ \ddot{x}+\tcboxmath[highlightstyle,octogon arc,arc is angular]{\frac{\omega_0}{Q}}\dot{x}+\omega_0^2 x=0 \]

\end{document} 

enter image description here

6
  • Interesting: no correction is required for the vertical position of the box!
    – Bernard
    Nov 26, 2017 at 17:30
  • yes looks great, I hate to have my fractions shrunk (so do the students) Nov 26, 2017 at 22:54
  • It is exactly what I wanted, i could create my commands and combine them, thx a lot ! Nov 26, 2017 at 23:37
  • @JeanLallemand: The correct way to say `thank you' is to accept the answer that fits most ;-)
    – user31729
    Nov 27, 2017 at 9:50
  • @ChristianHupfer what do you mean by that (remember i just started here) ? That I should only click on "this answer is usefull" for the best answer ? Nov 27, 2017 at 10:01
1

Here are two ways with pstricks.

Comments aside: the language option should be loaded with the document class, since babel 3.9, to ensure language-dependent packages be aware of the document main language. Also, you shouldn't use the $$ ... $$ construction, which is plain TeX, always prefer \[ ... \].

\documentclass[12pt,a4paper, french]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{amsmath,amssymb}
\usepackage[table]{xcolor}
\usepackage{psfrag}
\usepackage{fancybox}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} %% to compile with pdflatex -shell-escape under TeX Live or MacTeX, pdflatex --enable-write18 under MiKTeX
\usepackage{pgfplots}

\begin{document}

\[ \ddot{x}+\colorbox{red!10}{$\dfrac{\omega_0}{Q}$}\dot{x}+\omega_0^2 x=0 \]

\[ \ddot{x}+\raisebox{\dimexpr-0.5\height +0.25ex}{\psovalbox*[fillcolor = red!20]{$ \dfrac{\omega_0}{Q} $}}\dot{x}+\omega_0^2 x=0 \]

\[ \ddot{x}+\raisebox{\dimexpr-0.5\height +0.25ex}{\psframebox*[fillcolor = red!30, framearc =.6]{$ \dfrac{\omega_0}{Q} $}}\dot{x}+\omega_0^2 x=0 \]

\end{document} 

enter image description here

3
  • thx, actually this shrinks all fractions, so does the color box when I putt the whole equation in a color box, how can i fix this? Nov 26, 2017 at 22:53
  • @JeanLallemand: You're right. As I focused on obtaining the coloured background, I forgot that in a box, maths are typeset in text mode. For the present case, using \dfrac will ne enough. For more complex formulæ, you can begin $\displaystyle ... $, or even set for the current group \everypsbox{\displaystyle}. I've fixed the code, and updated the picture.
    – Bernard
    Nov 26, 2017 at 23:19
  • perfect, thx for all those precisions ( I have used \dfrac once for an exponential ) . I am new here but already love this site. Nov 27, 2017 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .