Math & ScienceTurn off fleqn for just one equation

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

Turn off fleqn for just one equation

Post by Singularity »

I'm having the opposite problem as this guy. I want to turn off fleqn for just one equation. I tried things like begin{center} and end{center} and \centering. But no luck. I did not find anything I could get working in ncctools, either. I'm trying to center the equations for standard deviation in the following MWE:

Code: Select all

\documentclass[fleqn,addpoints
%,answers
]{exam}
\usepackage{amsfonts,amsmath,amssymb,amsthm,mathtools}

\everymath{\displaystyle}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\begin{document}
\fbox{\parbox{5.5in}{
Equations for standard deviation:
\begin{equation*}
	s = \sqrt{\frac{\left(x-\bar{x}\right)^2}{n-1}} \qquad\qquad\qquad \sigma = \sqrt{\frac{\left(x-\mu\right)^2}{N}}
\end{equation*}
}}

\end{document}

Recommended reading 2024:

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

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Turn off fleqn for just one equation

Post by Johannes_B »

You can set the boolean locally to false.

Code: Select all

\listfiles
\documentclass[fleqn]{article}
\usepackage{mathtools}


\usepackage{etoolbox}
\newenvironment{cequation}{
	\makeatletter
	\setbool{@fleqn}{false}
	\makeatother
	\begin{equation*}
	}{\end{equation*}}
\begin{document}
\fbox{\parbox{5.5in}{
	Equations for standard deviation:
	\makeatletter
	\setbool{@fleqn}{false}
	\makeatother
	\begin{equation*}
		s = \sqrt{\frac{\left(x-\bar{x}\right)^2}{n-1}} \qquad\qquad\qquad \sigma = \sqrt{\frac{\left(x-\mu\right)^2}{N}}
	\end{equation*}
}}

\fbox{\parbox{5.5in}{
	Equations for standard deviation:
	\begin{equation*}
		s = \sqrt{\frac{\left(x-\bar{x}\right)^2}{n-1}} \qquad\qquad\qquad \sigma = \sqrt{\frac{\left(x-\mu\right)^2}{N}}
	\end{equation*}
}}

\fbox{\parbox{5.5in}{
	Equations for standard deviation:
	\begin{cequation}
		s = \sqrt{\frac{\left(x-\bar{x}\right)^2}{n-1}} \qquad\qquad\qquad \sigma = \sqrt{\frac{\left(x-\mu\right)^2}{N}}
	\end{cequation}
}}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply