0

I want to center this following code:

\documentclass[12pt,fleqn]{article}
\usepackage{bm}
\usepackage{amsmath}
\usepackage[overload]{empheq}

\newcommand*\widebox[1]{\fbox{\hspace{1em}#1\hspace{1em}}}
\newcommand*\rpos{\text{\textbf{r}}}

\begin{document}
    \begin{empheq}[box=\widebox]{align}
    \rpos&=x\,\hat{i}+y\,\hat{j}+z\,\hat{k},\nonumber\\
    \mathbf R &= (R_{\text{Terra}}+\text{h})\:\hat{k},\nonumber\\
    \bm{\mathcal R}&=\mathbf R + \rpos,\nonumber\\
    \bm{\omega}&=\omega(sin\lambda\:\hat{i}+cos\lambda\:\hat{k}).\nonumber\\ \nonumber
    \end{empheq}
\end{document}

Result

Any ideas?

  • 1
    Do you want the code centered in the box, or do you want the box centered across the line. p.s. Your code does not compile as is...please edit to make it compile. Welcome to the site. – Steven B. Segletes Oct 13 '16 at 11:26
  • 1
    Remove the last \\ \nonumber to center the equations vertically in the box. – gernot Oct 13 '16 at 11:39
  • 1
    Or, to center horizontally, remove fleqn class option and use gather* instead of align. Also you should be using align* and then there'd be no need for \nonumbers. – Guilherme Zanotelli Oct 13 '16 at 12:07
  • @StevenB.Segletes I want the box to be centered across the line. – J. Barbosa Oct 13 '16 at 12:25
  • @GuilhermeZ.Santos Thanks for the edit. But is there a way to supress the fleqn option just in this part of the code? – J. Barbosa Oct 13 '16 at 12:28
  • I don't know about that, I'll see and edit the answer if a workaround is found! :D – Guilherme Zanotelli Oct 13 '16 at 12:35
  • @J.Barbosa, I'm sorry but seems that you either use empheq without fleqn or you use nccmath's ceqn environment in conjunction with amsmath. See this link for reference on the nccmath thing. I saw in empheq manual the marginbox for fleqn documents but it didn't work as expected. – Guilherme Zanotelli Oct 13 '16 at 13:10

1 Answers1

2

To have unnumbered horizontal aligned equations remove the fleqn class option and use the gather* environment from amsmath without putting & alignment characters:

\documentclass[12pt]{article}
\usepackage{bm}
\usepackage{amsmath}
\usepackage[overload]{empheq}

\newcommand*\widebox[1]{\fbox{\hspace{1em}#1\hspace{1em}}}
\newcommand*\rpos{\text{\textbf{r}}}

\begin{document}
    \begin{empheq}[box=\widebox]{gather*}
    \rpos = x \, \hat{i} + y \, \hat{j} + z \, \hat{k}, \\
    \mathbf R = (R_{\text{Terra}} + \text{h}) \: \hat{k}, \\
    \bm{\mathcal R} = \mathbf R + \rpos, \\
    \bm{\omega} = \omega (\sin\lambda \: \hat{i}+ \cos\lambda\:\hat{k}). % Last '\\' is not placed!
    \end{empheq}
\end{document}

Notice that this is not usual equation aligment as the equations won't be aligned at the = sign. To align through equal sign and have unnumbered equations use the align* environment!

Also notice the use of \sin and \cos for proper upright sine and cosine functions.

enter image description here