Difference between \textwidth, \linewidth and \hsize

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


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).


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