3

Could you help me to create an environment out of this code:

\smallskip\centering\framebox[0.9\textwidth]{
\begin{minipage}[c]{0.8\textwidth}
\begin{eqnarray}
I & = & -\mu\frac{W}{L}\int_{V_{S}}^{V_{D}} Q_{m} \cdot \ud{}V_{ch} \\
v_{g} - \Delta\phi_{i} - v_{ch} + \ln(\frac{q_{int}}{2}) & = & 4 q_{g} + \ln(q_{g}) + \ln\left( 1 + q_{g}\frac{C_{ox}}{C_{Si}} \right) \\
i & \approx & -q_{mD}^2 + q_{mD} - (-q_{mS}^2 + q_{mS})
\end{eqnarray}
\[\mathrm{where:} \quad v_{x} = \frac{V_{x}}{U_{T}},\ q_{int} = \frac{e n_{i} t_{Si}}{4 C_{ox} U_{T}},\ q_{x} = \frac{Q_{x}}{4 C_{ox} U_{T}},\ C_{Si} = \frac{\varepsilon_{Si}} {t_{Si}}\]
\medskip
\end{minipage}}

I have in mind something like:

\newenvironment{\MyMathBox}
{\smallskip\centering\framebox[0.9\textwidth]{
\begin{minipage}[c]{0.8\textwidth}}
{\medskip
\end{minipage}}}

The eqnarray block must be implementable inside the environment.

Moriambar
  • 11,466

2 Answers2

6

enter image description here

Please always post complete documents defining all commands used (I made up something for \ud.

You need lrbox to save the contents into a box register which you can then put a frame around. As the comments have noted it's usually better to use ams alignments than eqnarray. (Not least as it handles moving the label out of the way of large entries, as shown in the image eqnarray isn't so good at that.)

\documentclass{article}

\newenvironment{mymathbox}
{\par\smallskip\centering\begin{lrbox}{0}%
\begin{minipage}[c]{0.8\textwidth}}
{\end{minipage}\end{lrbox}%
\framebox[0.9\textwidth]{\usebox{0}}%
\par\medskip
\ignorespacesafterend}


\begin{document}

\def\ud{}
\begin{mymathbox}
\begin{eqnarray}
I & = & -\mu\frac{W}{L}\int_{V_{S}}^{V_{D}} Q_{m} \cdot \ud{}V_{ch} \\
v_{g} - \Delta\phi_{i} - v_{ch} + \ln(\frac{q_{int}}{2}) & = & 4 q_{g} + \ln(q_{g}) + \ln\left( 1 + q_{g}\frac{C_{ox}}{C_{Si}} \right) \\
i & \approx & -q_{mD}^2 + q_{mD} - (-q_{mS}^2 + q_{mS})
\end{eqnarray}
\end{mymathbox}
\end{document}
David Carlisle
  • 757,742
  • It's almost perfect, there is just a problem with $\medskip$ command which doesn't seem to produce any result in the environment.
    \newcommand{\ud}{\mathrm{d}}
    
    – Michal Wolodzko Mar 01 '13 at 20:08
  • 3
    I love your example code, as it so perfectly demonstrates the shortcomings of the eqnarray environment. – Mico Mar 01 '13 at 20:13
  • @MichalWolodzko try it now with \par before each of the skips – David Carlisle Mar 01 '13 at 20:28
  • No, it still doesn't work: \newcommand{\ud}{\mathrm{d}} \newenvironment{mymathbox} {\par\smallskip\centering\begin{lrbox}{0}% \begin{minipage}[c]{0.8\textwidth}} {\end{minipage}\end{lrbox}% \framebox[0.9\textwidth]{\usebox{0}}% \par\medskip \ignorespacesafterend} – Michal Wolodzko Mar 01 '13 at 21:21
  • well that puts a medskip, perhaps you want more space: test with changing \medskip to \vspace{5cm} to check you get a big space to following text then reduce as desired... This is space after the box so doesn't show unless you add some following text – David Carlisle Mar 01 '13 at 22:16
  • Look at the effects of environment command and a plain text: in environment plain code – Michal Wolodzko Mar 02 '13 at 18:34
  • I have finally managed to solve the issue. Instead of placing \medskip at the very end I should have put it right before \end{minipage}: \newcommand{\ud}{\mathrm{d}} \newenvironment{mymathbox} {\smallskip\centering\begin{lrbox}{0}% \begin{minipage}[c]{0.8\textwidth}} {\medskip\end{minipage}\end{lrbox}% \framebox[0.9\textwidth]{\usebox{0}}% \smallskip \ignorespacesafterend} – Michal Wolodzko Mar 02 '13 at 18:42
1

Have you seen the solution with TiKZ at TeXample?

Here is a minimal working example:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\usepackage{amsmath,amssymb}


% Define box and box title style
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]

\newcommand{\fancybox}[2][Title of the box]{%
\begin{tikzpicture}
\node [mybox] (box){%
    \begin{minipage}{0.50\textwidth}
    #2
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {#1};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\end{tikzpicture}%
}


\begin{document}

\fancybox[MyTitle]{How is that?
I can put equations here as well
\begin{align}
   E \Psi &= \hat H \Psi
\end{align}
}

\end{document}

enter image description here

aignas
  • 1,306