8.19.5 \line

Synopsis:

\line(x_run,y_rise){travel}

Draw a line. It slopes such that it vertically rises y_rise for every horizontal x_run. The travel is the total horizontal change—it is not the length of the vector, it is the change in x. In the special case of vertical lines, where (x_run,y_rise)=(0,1), the travel gives the change in y.

This draws a line starting at coordinates (1,3).

\put(1,3){\line(2,5){4}}

For every over 2, this line will go up 5. Because travel specifies that this goes over 4, it must go up 10. Thus its endpoint is (1,3)+(4,10)=(5,13). In particular, note that travel=4 is not the length of the line, it is the change in x.

The arguments x_run and y_rise are integers that can be positive, negative, or zero. (If both are 0 then LaTeX treats the second as 1.) With \put(x_init,y_init){\line(x_run,y_rise){travel}}, if x_run is negative then the line’s ending point has a first coordinate that is less than x_init. If y_rise is negative then the line’s ending point has a second coordinate that is less than y_init.

If travel is negative then you get LaTeX Error: Bad \line or \vector argument.

Standard LaTeX can only draw lines with a limited range of slopes because these lines are made by putting together line segments from pre-made fonts. The two numbers x_run and y_rise must have integer values from −6 through 6. Also, they must be relatively prime, so that (x_run,y_rise) can be (2,1) but not (4,2) (if you choose the latter then instead of lines you get sequences of arrowheads; the solution is to switch to the former). To get lines of arbitrary slope and plenty of other shapes in a system like picture, see the package pict2e (https://ctan.org/pkg/pict2e). Another solution is to use a full-featured graphics system such as TikZ, PSTricks, MetaPost, or Asymptote.


Unofficial LaTeX2e reference manual