473

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.

1
  • 9
    In addition to the other helpful answers, a useful list with several lengths: LaTeX default lengths
    – quazgar
    Commented Jul 29, 2013 at 17:54

4 Answers 4

346

\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:

\begin{enumerate}
\item some text that contains a `here' table
      \begin{center}
      \begin{tabularx}{.9\linewidth}{lXX}
      ...
      \end{tabularx}
      \end{center}
      and some other text that follows.
\item ...
\end{enumerate}

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.

10
  • 3
    Couldn't the general advice for the width of the figure be to always use \linewidth? Commented May 1, 2011 at 3:08
  • 5
    I.e., the way that I think about it is that \linewidth is the most general of the lot, adapting to its current situation, whereas \textwidth and \columnwidth are fixed design-oriented lengths. (And \hsize should be avoided in LaTeX, generally speaking.) Commented May 1, 2011 at 12:45
  • 6
    @Will: there's the problem that we don't know a priori the value of \linewidth that will be used. For example, writing a \begin{figure}[h] environment in the middle of a list and using \linewidth will probably give a surprise.
    – egreg
    Commented May 1, 2011 at 13:10
  • 2
    I'm not sure if I follow. A figure is always set full-width; I'm not sure if you'd ever consider it ‘proper’ to put a figure inside a list like this and expect \linewidth to respect the list sizing. It seems fairly ludicrous to have a captioned figure as part of a list, don't you think? Commented May 1, 2011 at 14:59
  • 2
    @Will: I am actually putting figures (from standalone files) within an enumerated list. The same figure is used in different contexts and in one they happen to be part of a list. Commented May 17, 2011 at 5:57
177

I think the simplest way to describe the difference is as follows:

  • \hsize is a TeX primitive that should not be usually used in LaTeX
  • \textwidth is the (constant) width of the total text block
  • \columnwidth is the (constant) width of a single column of text
    (which is the same as \textwidth for a single column document)
  • \linewidth is a variable that represents the current size of the line of text, whether inside a column or a minipage or a list

In general, then, it's best to always use \linewidth if you are specifying the relative size of an image or a box, since it will adapt to the current situation.

Note: \linewidth also appears to work in table columns, not just text columns. See this answer for an example where a fixed-width parbox is used within a table cell (actually a multirow cell).

0
62

A test document in a twocolumn and onecolumnmode:

\documentclass[twocolumn]{article}
\parindent=0pt
\usepackage[paperheight=7cm]{geometry}
\begin{document}

\leavevmode\rlap{text:}\rule{\textwidth}{2pt}\par
\leavevmode\rlap{line:}\rule{\linewidth}{2pt}\par
\leavevmode\rlap{hsize:}\rule{\hsize}{2pt}\par
\leavevmode\rlap{column:}\rule{\columnwidth}{2pt}

\begin{itemize}
\item \rule{\textwidth}{5pt}
\item \rule{\linewidth}{5pt}
\item \rule{\hsize}{5pt}
\item \rule{\columnwidth}{5pt}
\end{itemize}

\onecolumn
\leavevmode\rlap{text:}\rule{\textwidth}{2pt}\par
\leavevmode\rlap{line:}\rule{\linewidth}{2pt}\par
\leavevmode\rlap{hsize:}\rule{\hsize}{2pt}\par
\leavevmode\rlap{column:}\rule{\columnwidth}{2pt}

\begin{itemize}
\item \rule{\textwidth}{5pt}
\item \rule{\linewidth}{5pt}
\item \rule{\hsize}{5pt}
\item \rule{\columnwidth}{5pt}
\end{itemize}

\end{document}

enter image description here

1
  • 14
    Thanks Herbert, but it would be really nice to have some general explanation for this lengths, for one- and two-column mode. Commented Apr 29, 2011 at 16:34
11

One difference is that in list and trivlist environments (i.e., including quote, quotation, and other such environments), \linewidth is smaller than \textwidth by the sum of \leftmargin and \rightmargin. I think I also remember that \hsize is what's used by the routine that breaks paragraphs into lines; since \leftmargin in a list is created by using the \parshape command, that routine doesn't need to be explicitly told about \leftmargin.

You must log in to answer this question.

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