5

How do I center the contents of each cell in the middle column? I am approximating it with \phantom, but there's got to be a better way.

\begin{alignat*}{3}
  &E&\quad&\mathrm{par}&&\quad\Sigma,\\
  &\Psi&\quad&\phantom{p}\mathrm{"}\phantom{r}&&\quad\frac{\epsilon V}{1+4\pi\epsilon F},\\
  &\Psi&\quad&\phantom{p}\mathrm{"}\phantom{r}&&\quad\frac{(1+4\pi\epsilon F)^2}{\epsilon}.
\end{alignat*}

thanks

6

At its heart the alignat environment is built on TeX's \halign. In that environment you can ignore the formatting specifications for a given column by issuing \omit. Thus writing

\omit\hfill text \hfill

will give you a centered column of text, since the column specification not only included the left/right alignment but also that the meterial is set as mathematics. It is probably best to create a separate command to provide this construction, which may then be used anywhere in an alignat, align or similar enviroment, at the beginning of a cell:

Sample output

\documentclass{article}

\usepackage{amsmath}

\newcommand{\ditto}{{''}}
\newcommand{\ccol}[1]{\omit\hfill #1\hfill}

\begin{document}

\begin{alignat*}{3}
  &E&\quad&\ccol{par}&\quad&\Sigma,\\
  &\Psi&&\ccol{\ditto}&&\frac{\epsilon V}{1+4\pi\epsilon F},\\
  &\Psi&&\ccol{\ditto}&&\frac{(1+4\pi\epsilon F)^2}{\epsilon}.
\end{alignat*}

\begin{align}
  E &= mc^2\\
  F &\ccol{is another quantity}\\
  G &= u^2 + v^2 - w^2 + x^2 - y^2 + z^2
\end{align}

\end{document}

Sould you wish to span multiple columns the relevant command is \multispan, e.g. \multispan{3}\hfill text \hfill will place text spread over three columns and centered.

Alternatively, as Harish Kumar suggests you can use array or tabular:

Second sample

\documentclass{article}

\usepackage{amsmath}

\newcommand{\ditto}{{''}}

\begin{document}

\begin{equation*}
  \begin{array}{r@{\quad}c@{\quad}l}
  E&\mathrm{par}&\Sigma,\\
  \Psi&\mathrm{\ditto}&\displaystyle\frac{\epsilon V}{1+4\pi\epsilon F},\\
  \Psi&\mathrm{\ditto}&\displaystyle\frac{(1+4\pi\epsilon F)^2}{\epsilon}.
  \end{array}
\end{equation*}

\begin{center}
  \begin{tabular}{r@{\quad}c@{\quad}l}
    \( E \)&par&\( \Sigma, \)\\
    \( \Psi \)&\ditto&\( \displaystyle\frac{\epsilon V}{1+4\pi\epsilon F}, \)\\
    \( \Psi \)&\ditto&\( \displaystyle\frac{(1+4\pi\epsilon F)^2}{\epsilon}. \)
  \end{tabular}
\end{center}
\end{document}

However, the default line spacing from alignat is better and you don't need to worry about adjusting the math styles.

  • According to my question here, using this command with alignat breaks numbering. – ominug Sep 14 '15 at 21:18
  • The problem arises when multiple \ccols are used on one line. overleaf.com/read/mvryrbzzgmkw – ominug Sep 14 '15 at 21:57
  • Indeed - it breaks if it is applied to an entry that is not the widest in its column. egreg's answer to your other question address that issue well. – Andrew Swann Sep 15 '15 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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