Math & ScienceHelp with alignat and columns

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Butters
Posts: 2
Joined: Fri Feb 25, 2011 5:31 pm

Help with alignat and columns

Post by Butters »

In the below code segment, I've managed to create two columns, but any attempt to create a third, to align the second column of vertical dots with the 'b' terms fails. How do I create this third alignment column?

Code: Select all

\begin{alignat*}{2}
&maximise\, \quad &&c_1x_1 + c_2x_2 + \ldots + c_nx_n \\
&subject\,to\, \quad &&a_{11}x_1 + a_{12}x_2 + \ldots + a_{1n}x_n \leq b_1 \\
& &&a_{21}x_1 + a_{22}x_2 + \ldots + a_{2n}x_n \leq b_2 \\
& &&\vdots \quad \vdots \\
& &&a_{m1}x_1 + a_{m2}x_2 + \ldots + a_{mn}x_n \leq b_m \\
&and\, \quad &&x_1 \geq 0, x_2 \geq 0, \ldots, x_n \geq 0
\end{alignat*}
Image

Also, how do I stop random parts of the text and functions from being in italics?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Stefan Kottwitz
Site Admin
Posts: 10308
Joined: Mon Mar 10, 2008 9:44 pm

Help with alignat and columns

Post by Stefan Kottwitz »

Hi,
Butters wrote:How do I create this third alignment column?
adjust the mandatory argument to alignat and use further ampersands.
Butters wrote:Also, how do I stop random parts of the text and functions from being in italics?
For text within math environments, use the \text macro. Here's complete example:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
&\text{maximise } \quad &&c_1x_1 + c_2x_2 + \ldots + c_nx_n &&\\
&\text{subject to } \quad &&a_{11}x_1 + a_{12}x_2 + \ldots + a_{1n}x_n &&\leq b_1 \\
& &&a_{21}x_1 + a_{22}x_2 + \ldots + a_{2n}x_n &&\leq b_2 \\
& &&\vdots \quad &&\quad\vdots \\
& &&a_{m1}x_1 + a_{m2}x_2 + \ldots + a_{mn}x_n &&\leq b_m \\
&\text{and }\quad &&x_1 \geq 0, x_2 \geq 0, \ldots, x_n \geq 0&&
\end{alignat*}
\end{document}
Stefan
LaTeX.org admin
Butters
Posts: 2
Joined: Fri Feb 25, 2011 5:31 pm

Help with alignat and columns

Post by Butters »

Thanks for the reply, it helped.

I've come up with the following code, which is closer to what I want, but not quite. It puts the vertical dots at the far right, and then aligns the b terms with the dots, rather than align the vertical dots with the b terms. In other words, I want the b terms to be in their natural positions, then the vertical dots to be aligned with them.

Code: Select all

\begin{alignat*}{4}
&\text{maximise }\quad &&c_1x_1 + c_2x_2 + \ldots + c_nx_n \\
&\text{subject to }&&a_{11}x_1 + a_{12}x_2 + \ldots + a_{1n}x_n &&&\leq b_1 \\
& &&a_{21}x_1 + a_{22}x_2 + \ldots + a_{2n}x_n &&&\leq b_2 \\
& &&\vdots &&&\vdots \\
& &&a_{m1}x_1 + a_{m2}x_2 + \ldots + a_{mn}x_n \leq b_m \\
&\text{and }&&x_1 \geq 0, x_2 \geq 0, \ldots, x_n \geq 0
\end{alignat*}
Image

Also, If I try introducing more alignment columns to align the various terms of the "subject to" equations, then everything goes a bit crazy.

Code: Select all

\begin{alignat*}{8}
&\text{maximise }\quad &&c_1x_1 + c_2x_2 + \ldots + c_nx_n \\
&\text{subject to }	&&a_{11}x_1 + &&&a_{12}x_2 + &&&&\ldots + a_{1n}x_n &&&&&\leq b_1 \\
& 					&&a_{21}x_1 + &&&a_{22}x_2 + &&&&\ldots + a_{2n}x_n &&&&&\leq b_2 \\
& 					&&\vdots &&&&&\vdots \\
& 					&&a_{m1}x_1 + &&&a_{m2}x_2 + &&&&\ldots + a_{mn}x_n &&&&&\leq b_m \\
&\text{and }&&x_1 \geq 0, x_2 \geq 0, \ldots, x_n \geq 0
\end{alignat*}
Image
Post Reply