13

as I was reading different question This one I've found code of array enviroment which preamble is quite unknown to be... I see what it does but I would like to understand it to be able use that technique for different situations... I understand what "c" "l" "r" mean but not the rest:

\[
\begin{array}{@{}r@{}l@{\quad}@{}r@{}l@{}}
a&{}=bbb & c&{}=\dfrac{x}{y} \\
aa&{}=bbbb & cc&{}=\dfrac{x}{y}
\end{array}
\]

I was trying to apply it in such a form that I have just one centered column and then right and left which are aligned according to = inside so I wrote \begin{array}{c@{\quad}@{}r@{}l@{}} and something inside environment according to example above but it gave me an error in a form that there are unknown characters in preamble of array... so obviously I do not understand those "@{}"resp "@{\quad}" parts and I wasn't able to find satisfactory answer on the web...

3 Answers3

21

On either side of each column of an array (or tabular) latex adds \arraycolsep) (or \tabcolsep for tabular) of whitespace, so normally there is 2\arraycolsep space between the columns.

If you go @{hello} then instead of adding space between the columns latex inserts hello in each row.

Sometimes you see forms such as r@{\mbox{--}}l which would make 2 & 3 appear as 2–3

The most common form though is @{} which doesn't add anything but removes the inter column space.

\quad is short for \hspace{1em} so @{\quad} changes the inter-column space from 2\arraycolsep (which is usually 10pt) to 1em (which is usually 10pt).

David Carlisle
  • 757,742
  • 1
    And that {} inside of array after & sign is also used for removing spaces? – Jozef Janočko Jan 17 '16 at 22:41
  • @JozefJanočko adding them actually. Compare $=1$ and ${}=1$ with the first form = is at the start so loses its infix relation spacing , here you want it to look like infix even though it is at the start of the cell so {} is added. – David Carlisle Jan 17 '16 at 22:44
  • @Mico thanks, fixed, had an "interesting" effect on the last sentence:-) – David Carlisle Jan 18 '16 at 07:42
9

Here is the formal references that mentions this notation in the preamble construction of tabular or array:

  • source2e (section 56.2 array and tabular environments, p 300)

    The PREAMBLE argument of an array or tabular environment can contain the following:

    • l,r,c : indicate where entry is to be placed.
    • | : for vertical rule
    • @{EXP} : inserts the text EXP in every column.
      \arraycolsep or \tabcolsep spacing is suppressed.
    • *{N}{PRE} : equivalent to writing N copies of PRE in the preamble.
      PRE may contain *{N’}{EXP’} expressions.
    • p{LEN} : makes entry in \parbox of width LEN.

It's also mentioned in Table 1 (p 2) of the array package documentation.

@{<stuff>} suppresses the inter-column separation and uses <stuff> instead.

Werner
  • 603,163
7

David Carlisle has already given a thorough answer as to what @{} and @{\quad} do. I'd like to add an observation regarding how the code for the array could have been set up more elegantly in the first place, in a way that would have avoided the need for the five [5!] instances of the @{} directive.

Specifically, by inserting the instruction \setlength\arraycolsep{0pt} immediately after \[, all five instances of @{} could have been avoided, streamlining the code that sets up the structure of the array:

\documentclass{article}
\usepackage{amsmath} % for "\dfrac" macro
\begin{document}
\[
  \setlength\arraycolsep{0pt} % default value: 5pt
  \begin{array}{rl @{\quad} rl}
     a&{}=bbb  &  c&{}=\dfrac{x}{y} \\[3ex]
    aa&{}=bbbb & cc&{}=\dfrac{x}{y}
  \end{array}
\]
\end{document}
Mico
  • 506,678