Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Really basic question, probably already answered but couldn't find anything.

I have this code:

\documentclass[a4paper]{scrreprt}
\usepackage{fontspec}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
  x_j = 1,\quad y_j = 2,\quad z_j = 3 \qquad \text{for }j=1, 2, 3, \dots, n
\end{equation*}

\end{document}

What I get is this:

enter image description here

But I want something like this (the "for j"-part should be ignored when the equation is centered):

enter image description here

Probably it would look better, if the "for j"-part is aligned to the right margin, unfortunately I don't know how to do that, too.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Just load mathtools instead of amsmath (it loads the latter) and use its \mathrlap command. You may put the \qquad inside the \rlap or not. In my opinion, if you put it inside, the main part of the equation doesn't look centred to the reader,though it is.

You must also be aware the condition might overlap the right margin. In such a case, I would one of the multi-line amsmath environment and put the condition on a separate line.

\documentclass[a4paper]{scrreprt}
\usepackage{fontspec}
\usepackage{mathtools}
\usepackage[showframe, nomarginpar]{geometry}

\begin{document}

\begin{equation*}
  x_j = 1,\quad y_j = 2,\quad z_j = 3 \qquad\mathrlap{\text{for }j=1, 2, 3, \dots, n}
\end{equation*}

\begin{equation*}
  x_j = 1,\quad y_j = 2,\quad z_j = 3 \mathrlap{\qquad\text{for }j=1, 2, 3, \dots, n}
\end{equation*}

\begin{equation*}
  x_j = 1,\quad y_j = 2,\quad z_j = 3 \qquad \text{for }j=1, 2, 3, \dots, n
\end{equation*}

\end{document} 

enter image description here

share|improve this answer
    
I'd put the \qquad inside \mathrlap; one should be aware that the condition might stick outside the margin. –  egreg Jul 14 at 12:19
    
You're perfectly right. I'll change that at once, thanks. –  Bernard Jul 14 at 12:34

You could align the condition to the right margin and center the equation to the rest of the line using flalign.

\documentclass{scrreprt}
\usepackage{fontspec}
\usepackage{amsmath}% loads also amsmath

\usepackage{showframe}% to show the page layout

\begin{document}

\begin{flalign*}
&&x_j = 1,\quad y_j = 2,\quad z_j = 3 &&\text{for }j=1, 2, 3, \dots, n&
\end{flalign*}

\end{document}

enter image description here


Only if you are sure that the equation and the condition will not overlap each other, you can use \mathllap to ignore the condition while centering the equation to the whole line.

\documentclass{scrreprt}
\usepackage{fontspec}
\usepackage{mathtools}% loads also amsmath

\usepackage{showframe}% to show the page layout

\begin{document}

\begin{equation*}
x_j = 1,\quad y_j = 2,\quad z_j = 3
\end{equation*}

\begin{flalign*}
&&x_j = 1,\quad y_j = 2,\quad z_j = 3 &&\mathllap{\text{for }j=1, 2, 3, \dots, n}
\end{flalign*}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.