Math & ScienceThe best way to emphasize equations ?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

The best way to emphasize equations ?

Post by Cham »

I need to emphasize some mid-paragraph equations. Of course, I'm using the \begin{equation} ... \end{equation} environment, and I tried the \boxed{ } option. However, the box is often too small around the equation, which doesn't "breathe well" inside the box. I tried adding some invisible characters inside the box, like \phantom{\Big|}, so the box becomes larger, but the results aren't very satisfying.

What do you suggest, to make a nice looking emphasized equation ?
Last edited by Cham on Wed Jun 29, 2011 8:54 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

The best way to emphasize equations ?

Post by localghost »

The empheq package from the mh bundle is your friend.


Thorsten
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

The best way to emphasize equations ?

Post by Cham »

I'm yet unable to make it to work. :( For example, I used this code :

Code: Select all

\begin{empheq}[boxtype=\fbox]
	\begin{equation}
		\label{hamiltonian}
			H(q, p) = \tensor{\dot q}{^i} \hspace{1pt} \tensor{p}{_i} - L.
	\end{equation}
	\end{empheq}
I'm getting several error messages when I try to compile it. Of course, I declared the \usepackage{empheq} in my preamble.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

The best way to emphasize equations ?

Post by localghost »

Please get used to always providing a minimal example that is compilable as is. It is essential for instant help. Especially in cases where the problem is much more complicated.

You didn't use the »empheq« environment correctly. This environment needs a certain syntax as described in the package manual.

Code: Select all

\documentclass[11pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}   % loads »amsmath«
\usepackage{empheq}
\usepackage{tensor}

\begin{document}
  \begin{empheq}[box=\fbox]{equation}\label{eqn:hamiltonian}
    H(q,p) = \tensor{\dot{q}}{^i}\,\tensor{p}{_i}-L
  \end{empheq}
\end{document}
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

The best way to emphasize equations ?

Post by Cham »

Haa ! Ok, now it's working. Wasn't obvious !

EDIT : Wow ! Now it's awesome :shock: . This is exactly what I need !

Again, thanks A LOT for all of your precious help ! ;)
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

The best way to emphasize equations ?

Post by Cham »

I'm back on this topic with a desire !

Currently, my emphasized equations are all working great, but I would like to add a simple black line all around the gray box (no white space), or even a double-frame. Here's a compilable example of a gray box around an equation :

Code: Select all

\documentclass[11pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{empheq}
\usepackage{tensor}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{someGray}{RGB}{230,230,230}

\begin{document}
  \begin{empheq}[box={\setlength{\fboxsep}{10pt}\colorbox{someGray}}]{equation}
    H(q,p) = \tensor{\dot{q}}{^i}\,\tensor{p}{_i}-L
  \end{empheq}
\end{document}
How should I modify that example to add a black line around the gray box ?

What about a black double-frame around the gray box, for the most extremely important equations ?

The empheq package documentation isn't obvious about this !
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

The best way to emphasize equations ?

Post by Cham »

I'VE FOUND IT ! :D

Geez, I had to experiment a lot before finding this one !

Here's a compilable code to emphasize equations with a gray box, and a gray box with a red frame. The colors can be edited very easily.

Code: Select all

\documentclass[11pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{empheq}
\usepackage{tensor}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{medGray}{RGB}{230,230,230}

\newenvironment{important}[2][]{
	\setkeys{EmphEqEnv}{#2}
	\setkeys{EmphEqOpt}{box={\setlength{\fboxsep}{10pt}\colorbox{medGray}},#1}
	\EmphEqMainEnv}
{\endEmphEqMainEnv}

\newenvironment{tres important}[2][]{
	\setkeys{EmphEqEnv}{#2}
	\setkeys{EmphEqOpt}{box={\setlength{\fboxsep}{10pt}\fcolorbox{red}{medGray}},#1}
	\EmphEqMainEnv}
{\endEmphEqMainEnv}

\begin{document}

  \begin{tres important}{equation}
	H(q,p) = \tensor{\dot{q}}{^i}\,\tensor{p}{_i}-L
  \end{tres important}

  \begin{important}{equation}
	H(q,p) = \tensor{\dot{q}}{^i}\,\tensor{p}{_i}-L
  \end{important}

\end{document}
Here's a preview :
box.jpg
box.jpg (9.84 KiB) Viewed 12953 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: The best way to emphasize equations ?

Post by Stefan Kottwitz »

Nice solution, thanks for posting the complete example with screenshot!

Stefan
LaTeX.org admin
Post Reply