GeneralNew Command for a 'minipage' within a Frame

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Vio
Posts: 2
Joined: Thu Aug 25, 2011 4:55 pm

New Command for a 'minipage' within a Frame

Post by Vio »

Hi,

I've been using LaTeX for about a month or so and I'm amazed by its capacity. My documents mainly contain equations. I use fleqn on the documentclass option, since I prefer most of my equations flushed to the left.

Code: Select all

\documentclass[12pt,a4paper,fleqn]{article}
However, the occasional important equations will be centred. Typical code:

Code: Select all

\begin{center}
\fbox{%
\begin{minipage}[h]{270pt}
\[ \xi\mathcal{L} + \sum_{(\alpha)}\left[\eta^{(\alpha)} 
- \xi\dot{q}^{(\alpha)}\right]\frac{\partial L}{\partial\dot{q}^{(\alpha)}} 
- G ~=~ const. \]
\end{minipage}}
\end{center}
Is it possible to define a single command to do the above where I could input an equation as well as the height and width of the box? For example:

Code: Select all

\centereqn{<height of box>}{<width of box>}{<equation>}
Your help would be much appreciated and any feedback on more elegant methods are also welcomed :D .

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

ahmedsalahais
Posts: 14
Joined: Sat Mar 19, 2011 11:17 pm

New Command for a 'minipage' within a Frame

Post by ahmedsalahais »

I wounder why do you want to specify the height of the box? it doesn't make any sense as the box will automaticly stretch vertically to contain whatever it holds. In such case, you only need to pass the box position {t, h, ... etc.}, the box width, and the equation itself. Although i'm still learning, but i think this will work:

Code: Select all

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

\newcommand{\centereqn}[3]
{
\begin{center}
\fbox{
	\begin{minipage}[#1]{#2}
		#3
	\end{minipage}
	}
\end{center}
}
	
\begin{document}

\centereqn{h}{4in}{\[ \xi\mathcal{L} + \sum_{(\alpha)}\left[\eta^{(\alpha)} 
- \xi\dot{q}^{(\alpha)}\right]\frac{\partial L}{\partial\dot{q}^{(\alpha)}} 
- G ~=~ const. \]}

\end{document}
Vio
Posts: 2
Joined: Thu Aug 25, 2011 4:55 pm

New Command for a 'minipage' within a Frame

Post by Vio »

Hi, Thanks very much for your helpful reply. Your code works perfectly.
The reason why I needed to adjust the height was that in some instances the equation wouldn't vertically centre itself within the box. Here's an example:

Code: Select all

\documentclass[12pt,a4paper,fleqn]{article}
\usepackage{amsmath,amsfonts,amssymb}

\newcommand{\centereqn}[3]
{
\begin{center}
\fbox{
   \begin{minipage}[#1]{#2}
      #3
   \end{minipage}
   }
\end{center}
}
   
\begin{document}

\centereqn{h}{3.5in}{%
\[ \therefore~~ \xi \mathcal{L} + (\eta - \xi\dot{q})\frac{\partial \mathcal{L}}
{\partial\dot{q}} - G ~=~ const.  \]
}

\end{document}
I avoid this by using a \noindent prior to the equation. However, I fell that the output can be improved.

Code: Select all

\centereqn{!h}{3.5in}{\noindent
\[ \therefore~~ \xi \mathcal{L} + (\eta - \xi\dot{q})\frac{\partial \mathcal{L}}
{\partial\dot{q}} - G ~=~ const.  \]
}
Post Reply