6

This almost looks like what I would like to have

enter image description here

but the space between, for example, $f_1($ and $v_1$ is too large.

How can I fix this?


I got this with

\begin{equation}
  \begin{array}{llllll}
    f_1( & v_1, & v_2  &     &     & ) = 0 \\
    f_2( &      & v_2, & v_3 &     & ) = 0 \\
    f_3( &      & v_2, &     & v_4 & ) = 0 \\
    f_4( & v_1, &      &     & v_4 & ) = 0 
  \end{array}
\end{equation}

I also tried \mathtt and lots of \ but the alignment was always a little bit off (due to the subscript?) and LaTeX tips: Displayed Math says that I shouldn't insert spaces like that. The \quad proposed there inserted too much space.

  • On an unrelated topic: how can I get this site to display the right thing when I type $f_1($ ? – Ali Nov 21 '12 at 16:28
  • 1
    This site doesn't use MathJax, because we want to talk about TeX code. Just enclose inline code in backquotes ` as I did in my edit. – egreg Nov 21 '12 at 16:33
9

One way to reduce the spacing between the columns is to use @{}

enter image description here

I've put @{} between every column, but of course you can use it just on the columns that you wish.

You can think of the @{<stuff>} operation as adding <stuff> to every element in that column.

\documentclass{article}


\begin{document}

Original
\begin{equation}
  \begin{array}{llllll}
    f_1( & v_1, & v_2  &     &     & ) = 0 \\
    f_2( &      & v_2, & v_3 &     & ) = 0 \\
    f_3( &      & v_2, &     & v_4 & ) = 0 \\
    f_4( & v_1, &      &     & v_4 & ) = 0 
  \end{array}
\end{equation}

New
\begin{equation}
  \begin{array}{@{}l@{}l@{}l@{}l@{}l@{}l@{}}
    f_1( & v_1, & v_2  &     &     & ) = 0 \\
    f_2( &      & v_2, & v_3 &     & ) = 0 \\
    f_3( &      & v_2, &     & v_4 & ) = 0 \\
    f_4( & v_1, &      &     & v_4 & ) = 0 
  \end{array}
\end{equation}

\end{document}

Suggested by @egreg: you can use this idea to put \, after columns 2, 3, and 4, which gives

screenshot

\begin{equation}
  \begin{array}{@{}l@{}l@{\,}l@{\,}l@{\,}l@{}l@{}}
    f_1( & v_1, & v_2  &     &     & ) = 0 \\
    f_2( &      & v_2, & v_3 &     & ) = 0 \\
    f_3( &      & v_2, &     & v_4 & ) = 0 \\
    f_4( & v_1, &      &     & v_4 & ) = 0 
  \end{array}
\end{equation}

As @barbarabeeton pointed out, it doesn't seem necessary to use 6 columns; 5 columns will work ok

\begin{equation}
  \begin{array}{l@{\,}l@{\,}l@{\,}l@{}l@{}}
    f_1( v_1, & v_2  &     &     & ) = 0 \\
    f_2(      & v_2, & v_3 &     & ) = 0 \\
    f_3(      & v_2, &     & v_4 & ) = 0 \\
    f_4( v_1, &      &     & v_4 & ) = 0 
  \end{array}
\end{equation}

I assume you have the last column empty so that the closing ) will be aligned.

  • 1
    I'd add @{\,} after columns 2, 3 and 4 instead of @{}, to get the correct spacing after the commas. – egreg Nov 21 '12 at 16:38
  • @egreg Actually \begin{array}{@{}lllll@{}l@{}} looks like exactly what I wanted. Awesome, thank you both! – Ali Nov 21 '12 at 16:40
  • @Ali The spacings you get are too large, in my opinion. – egreg Nov 21 '12 at 16:41
  • @Ali you're welcome :) I put egreg's comment in there, just for reference – cmhughes Nov 21 '12 at 16:43
  • 1
    @cmhughes -- i'm confused. why are 6 columns needed? (columns 1 and 6 are always empty.) why wouldn't just 4 do? – barbara beeton Nov 21 '12 at 16:48
0

Reducing Horizontal Spacing

The negative space \! may seem like an odd thing to use but take the following example:

  \left(
    \begin{array}{c}
      n \\
      r
    \end{array}
  \right) = \frac{n!}{r!(n-r)!}

Image #1 - too much space

The matrix-like expression for representing binomial coefficients is too padded. There is too much space between the brackets and the actual contents within. This can easily be corrected by adding a negative space after the left bracket and before the right bracket.

  \left(\!
    \begin{array}{c}
      n \\
      r
    \end{array}
  \!\right) = \frac{n!}{r!(n-r)!}

Image #2 - reduced space

In any case, adding some spaces manually should be avoided whenever possible: it makes the source code more complex and it's against the basic principles of a 'What You See is What You Mean' approach.

The best thing to do is to define some commands using all the spaces you want and then, when you use your command, you don't have to add any other space. Later, if you change your mind about the length of the horizontal space, you can easily change it modifying only the command you defined before.

Let us use an example: you want the d of a dx in an integral to be in roman font and a small space away from the rest. If you want to type an integral like \int x \, \mathrm{d} x, you can define a command like this:

    \newcommand{\dd}{\mathop{}\,\mathrm{d}}

in the preamble of your document. We have chosen \dd just because it reminds the "d" it replaces and it is fast to type. Doing so, the code for your integral becomes \int x \dd x. Now, whenever you write an integral, you just have to use the \dd instead of the "d", and all your integrals will have the same style. If you change your mind, you just have to change the definition in the preamble, and all your integrals will be changed accordingly.

  • Welcome! Shouldn't \dd be defined by \mathop{}\!d (or whatever shape you want for the d)? And do you know about \binom? – egreg May 22 '18 at 9:09
  • @egreg - Thanks. I visit here often enough that registering seemed more friendly and useful than lurking. I was looking online for negative space, without using kern, and came across this question (without the answer I was looking for); later when I found the answer I came back here to add it to this question. Since I know MathJax a bit better than Tex I copied the example from the link without fixing (or ruining someone else's expert answer). \binom is higher up the page. Feel free to edit and improve my answer. – Rob May 22 '18 at 12:42

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.