[Tex/LaTex] Difference between \textwidth, \linewidth and \hsize


The three lengths \textwidth, \linewidth and \hsize seem to all hold the width of the current line. At least I never saw some real difference between \textwidth and \linewidth in my code. Both seem to be identical even when changed, e.g. by a minipage environment.

Could someone give me an elaborate explanation of the differences between these lengths? I like to understand them in detail. I know that the first two are from LaTeX and the latter one from plainTeX.

There is also \columnwidth which seems to be identical to \linewidth or \textwidth in one-column mode, right? Except when the line is reduced by a minipage or quote etc. environment.

Best Answer

\hsize is the main parameter that TeX uses when typesetting: whenever it finishes a paragraph it looks at the current value of \hsize for breaking it into horizontal boxes. Next, there are \leftskip and \rightskip and possibly other paragraph shape parameters (\hangindent and \hangafter or the more general \parshape).

LaTeX uses an indirect approach and maintains many \...width parameters.

\textwidth is generally the global width of the text area, while \columnwidth is the width of a column of text (it will be different from \textwidth when typesetting in two or more columns). However, inside a minipage, \textwidth will be set to the given argument along with \hsize, \columnwidth, and \linewidth (they will revert to the previous values at the end of the minipage because it forms a group). Note that \parbox doesn't reset \textwidth; the size is available as \linewidth.

The parameter \linewidth contains the line length inside a list (or derived) environment and it may change in a nested list (while \hsize, \textwidth and \columnwidth don't change).

When we have to specify a length depending on current conditions, we have to use the correct parameter. For example, the width of a figure should be specified in terms of \columnwidth in a figure environment and of \textwidth in a figure* environment; however this is done rarely when it's known that the document will be typeset in one column format. The same should be for a tabular* or tabularx environment.

Instead, when we need something centered with respect to a line in a list, we should use \linewidth:

\item some text that contains a `here' table
      and some other text that follows.
\item ...

In this case it would be wrong to use \textwidth or \columnwidth, as the line length is "unknown" at typing time.

Notice that LaTeX uses \hangindent only for typesetting sectional titles and \leftskip and rightskip for \centering, \raggedright and \raggedleft; the indentation of a list environment is obtained via \parshape.