3

I have a table in which a column looks like this: a column in a table

I want to align the $\ge$ signs one below the other. How do I achieve this?

I was also hoping that the solution would be generalizable, in the sense that similar to normal align environment, I could have multiple 'columns' of alignment inside this column (i.e. coeffs of $v_1$ would be aligned, coeffs of $v_2$ would be aligned, and so on). So I guess I want something more general than right alignment.

Also note that I have some columns to the left and right of this column.

Note: I am using array environment to introduce math mode throughout the column (| >{$}c<{$} |).

5
  • If you have exactly this, use the column qualifier.
    – Bernard
    Commented Dec 8, 2015 at 16:39
  • 1
    @Bernard you mean r :-) Commented Dec 8, 2015 at 16:39
  • @David Carlisle: Oh yes! Should I be an ill-converted left hander, without knowing it?
    – Bernard
    Commented Dec 8, 2015 at 16:47
  • @Bernard I am looking for something general than simple right alignment, hoping that I can use the same solution for multiple alignments.
    – taninamdar
    Commented Dec 8, 2015 at 17:09
  • It was just a sugestion, for simple situations.
    – Bernard
    Commented Dec 8, 2015 at 17:15

2 Answers 2

2

Here's a way to embed the math-y material in a three-column tabular environment. Note the use of a two-column array environment, where the columns are separated automatically by \ge (greater than or equal) symbols.

Aside: I find all those horizontal lines highly distracting. If it were my table, I'd get rid of the interior horizontal lines.

enter image description here

\documentclass{article} 
\begin{document}
\begin{table}
\centering
\begin{tabular}{|l|@{}l@{}|l|}
  \hline
  column 1 material & 
  $\begin{array}[t]{ r @{{}\ge{}} l }
                      v_2 & 0 \\ \hline
      (k-1)v_2 - (k+1)v_3 & 0 \\ \hline
                     kv_3 & 0 \\ \hline
              kv_2 - kv_3 & 0 \\ \hline
    (k+1)v_1 + (-2k+1)v_2 & 1 
  \end{array}$ &
  column 3 material \\ 
  \hline
\end{tabular}
\end{table}

\end{document}

Addendum: It's straightforward to extend this array-based approach to handle not just two columns but, say, six columns:

enter image description here

\documentclass{article} 
\usepackage{array}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|l|@{}l@{}|l|}
  \hline
  column 1 material & 
  $\begin{array}[t]{ *{2}{r @{} >{{}}c<{{}} @{}} r @{{}\ge{}} l }
      & &      v_2 &   &          & 0 \\ \hline
      & & (k-1)v_2 & - & (k+1)v_3 & 0 \\ \hline
      & & & &                kv_3 & 0 \\ \hline
      & &     kv_2 & - &     kv_3 & 0 \\ \hline
  (k+1)v_1 & + & (-2k+1)v_2 & & & 1 
  \end{array}$ &
  column 3 material \\ 
  \hline
\end{tabular}
\end{table}
\end{document}
7
  • Can you explain the meaning of r @{{}\ge{}} l? I think this, if I tweak it, will be able to align in multiple columns within this column. (i.e. all v_1 coeffs aligned, all v_2 coeffs aligned, all v_3 coeffs aligned and the \ge aligned).
    – taninamdar
    Commented Dec 8, 2015 at 17:28
  • @taninamdar - I've posted an addendum with a generalized solution that performs alignment on all three v_i elements (as well as the \ge symbol). The somewhat forbidding looking @{} >{{}}c<{{}} @{} expression serves to get the right amount of spacing around the + and - symbols (which are "binary operators" in TeX jargon). The @{{}\ge{}} term inserts a \ge symbol between the v_3 column and the very last column -- no need to type \ge every single time -- again with the correct amount of spacing (\ge is a "relational operator" in TeX jargon).
    – Mico
    Commented Dec 8, 2015 at 17:37
  • Suppose I am okay with not having such a fine-tuning of spacing around + and -, could that expression be simplified?
    – taninamdar
    Commented Dec 8, 2015 at 17:40
  • @taninamdar - Absolutely: Just omit the @{} particles, replace >{{}}c<{{}} with c, and replace @{{}\ge{}} with @{\ge}. (I'm pretty sure, though, that you'll prefer the solution with the well-spaced binary and relational operators...)
    – Mico
    Commented Dec 8, 2015 at 17:43
  • Does the *{2} stand for number of 'columns' - 1?
    – taninamdar
    Commented Dec 8, 2015 at 17:46
2

Here are three ways of achieving your goal, depending on what the rest of your table looks like:

\documentclass{article}

\usepackage{mathtools,array}

\begin{document}

\[
  \begin{array}{r@{}>{{}}l}
    \multicolumn{2}{c}{\text{Some length heading for the LHS and RHS}} \\
    \hline
                      v_2 & \geq 0 \\
      (k-1)v_2 - (k+1)v_3 & \geq 0 \\
                     kv_3 & \geq 0 \\
              kv_2 - kv_3 & \geq 0 \\
    %\hspace{3em}% Possible horizontal alignment required
    (k+1)v_1 + (-2k+1)v_2 & \geq 1
  \end{array}
\]

\newcommand{\LHS}{\phantom{(k+1)v_1 + (-2k+1)v_2}}%
\[
  \begin{array}{c}
    \text{Some length heading for the LHS and RHS} \\
    \hline
                    \LHS\mathllap{v_2} \geq 0 \\
    \LHS\mathllap{(k-1)v_2 - (k+1)v_3} \geq 0 \\
                   \LHS\mathllap{kv_3} \geq 0 \\
            \LHS\mathllap{kv_2 - kv_3} \geq 0 \\
                 (k+1)v_1 + (-2k+1)v_2 \geq 1
  \end{array}
\]

\[
  \begin{tabular}{>{\centering\arraybackslash}p{20em}}
    Some length heading for the LHS and RHS \\
    \hline
    $\begin{aligned}
                        v_2 &\geq 0 \\
        (k-1)v_2 - (k+1)v_3 &\geq 0 \\
                       kv_3 &\geq 0 \\
                kv_2 - kv_3 &\geq 0 \\
      (k+1)v_1 + (-2k+1)v_2 &\geq 1
    \end{aligned}$
  \end{tabular}
\]

\end{document}

The first construction may require some additional horizontal adjustment in order to make the alignment fit properly across the column:

enter image description here

The second uses the technique listed in Alignment of equals sign in multiple align environments with a combination of \phantoms and overlaps:

enter image description here

The third inserts an aligned in order to achieve the alignment. It requires a pre-specified column width (which can be measured, if needed):

enter image description here


As a side-note: The right-hand sides are all of similar size, so using an r-column would suffice. However, I assume the array construction is far larger than depicted and an r-column might affect other (currently invisible) layout.

3
  • Hm, I am kinda confused. This isn't the only column in my table, there are some columns to the left and to the right of this column. If I understand this correctly, these solution treat them as one cell (i.e. part of one row), is that correct?
    – taninamdar
    Commented Dec 8, 2015 at 17:06
  • Also, I don't think I can generalize any of these to align multiple times, i.e. aligning coefficients of v_1, v_2 etc, along with the last inequality signs.
    – taninamdar
    Commented Dec 8, 2015 at 17:10
  • @taninamdar: Next time you post a question, please provide a broader context rather than just the essential information...
    – Werner
    Commented Dec 8, 2015 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .