# Align denominator of fraction to left

The highlighted part has the equation centred, which looks rather imbalance with the top equation, is it possible to align the highlighted part to the left? Below is the code I am using.

$$~\label{eq:prob1} p_k(s)= \begin{cases} \displaystyle\frac{c_k-q_k(s)}{c_k- \overline{c_k}} & if\ q_k(s) > \overline{c_k} \\ 1 & if\ q_k(s) \leq \overline{c_k} \end{cases}$$


-
It doesn't look unbalanced to me. –  egreg Nov 25 '12 at 22:38

You can use

\frac{c_k-q_k(s)}{c_k- \overline{c_k}\hfill}


to force the denominator to the left

-

The fraction doesn't look unbalanced to me. However, some small refinements might improve its appearance.

The main problem I see is in the overline, which sticks too much to the right. Here are six proposals (the twocolumn option is just for getting a reduced text width)

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\begin{document}
\begin{gather}
\frac{c_k-q_k(s)}{c_k- \overline{c_k}}\\
\frac{c_k-q_k(s)}{c_k- \overline{c_k}\,}\\
\frac{c_k-q_k(s)}{c_k- \overline{c_k\mkern-2mu}\mkern2mu}\\
\frac{c_k-q_k(s)}{c_k- \overline{c_k\mkern-2mu}\mkern2mu\,}\\
\frac{c_k-q_k(s)}{c_k- \mkern1.5mu\overline{\mkern-1.5mu c_k\mkern-2mu}\mkern2mu}\\
\frac{c_k-q_k(s)}{c_k- \mkern1.5mu\overline{\mkern-1.5mu c_k\mkern-2mu}\mkern2mu\,}
\end{gather}
\end{document}


The trick for the \mkern can of course be hidden in a macro; the \, at the end of the second and fourth examples pushes the denominator a bit to the left. In the fifth and sixth examples, the bar overhang of the bar is reduced also at the left.

Pushing the denominator all the way to the left is, in my opinion, wrong.

-

The \hfill solution works in this particular case only because identical terms are used as the first term for both the denominator and numerator. For more general cases, this may not quite provide the desired alignment. For example, if the numerator contained w_k and the denominator c_k, using just \hfill would provide the alignment as illustrated by the last example below.

This solution provides an \AlignMe macro that has one optional parameter and two mandatory parameters:

\AlignMe[<alignment>]{<content to determine space>}{<content to be typeset>}


where <alignment> can be the usual single letters of left, center, and right.

Below are a few examples illustrating this and comparing to the \hfill solution where the alignment of the first term is adjusted and the alignment of the minus sign remains intact:

## Notes:

• You should use \text{if} instead of if as Hendrik Vogt commented.
• My personal preference would be equation (1). Even though that results in the denominator not being centered with respect to the vinculum being

## Code:

\documentclass{article}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{calc}

% Add color here to simplify comparrison of the alignment
\newcommand{\CK}{\textcolor{red}{c_k}}
\newcommand{\CkBar}{\textcolor{blue}{\overline{c_k}}}

\newcommand*{\AlignMe}[3][c]{%
\makebox[\widthof{$#2$}][#1]{$#3$}}%
\begin{document}\noindent
Using \verb|\AlignMe[r]| for first and \verb|\AlignMe[l]| for second term:
$$p_k(s)= \begin{cases} \dfrac{w_k -q_k(s)}{\AlignMe[r]{w_k}{\CK} - \AlignMe[l]{q_k(s)}{\CkBar}} & \text{if } q_k(s) > \overline{c_k} \\ 1 & \text{if } q_k(s) \leq \overline{c_k} \end{cases}$$
%
Using \verb|\AlignMe[r]| and \verb|\hfill|:
$$p_k(s)= \begin{cases} \dfrac{w_k -q_k(s)}{\AlignMe[r]{w_k}{\CK} - \CkBar\hfill} & \text{if } q_k(s) > \overline{c_k} \\ 1 & \text{if } q_k(s) \leq \overline{c_k} \end{cases}$$
%
Using \verb|\AlignMe[r]| for first and \verb|\AlignMe[c]| for second term:
$$p_k(s)= \begin{cases} \dfrac{w_k -q_k(s)}{\AlignMe[r]{w_k}{\CK} - \AlignMe[c]{q_k(s)}{\CkBar}} & \text{if } q_k(s) > \overline{c_k} \\ 1 & \text{if } q_k(s) \leq \overline{c_k} \end{cases}$$
%
For comparrison, using \verb|\hfill|:
$$p_k(s)= \begin{cases} \dfrac{w_k -q_k(s)}{\CK - \CkBar\hfill} & \text{if } q_k(s) > \overline{c_k} \\ 1 & \text{if } q_k(s) \leq \overline{c_k} \end{cases}$$
\end{document}

-
You also use \phantom{} to create whitespace of desired character width. In this case \phantom{(s)},
\dfrac{c_k-q_k(s)}{c_k- \overline{c_k}\phantom{(s)}}

Also I replaced \displaystyle\frac by \dfrac instead.