Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

(Herbert gave me some explanation about the first two lengths a while ago in a comment thread of us, but I thought it's better as a question.)

share|improve this question
4  
I hate when people withhold votes because the question would pass a milestone (e.g. 100 votes). I find this question useful! Have a vote. –  Ryan Reich Jun 26 '13 at 0:08
1  
Funny, I've been swayed (from on-the-fence, if that exists) to up vote if only for milestone counts. It's an achievement well worth noting!! –  Sean Allred Jul 1 '13 at 12:00
3  
In addition to the other helpful answers, a useful list with several lengths: LaTeX default lengths –  quazgar Jul 29 '13 at 17:54

4 Answers 4

up vote 109 down vote accepted

\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 or \parbox, \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 or \parbox that form a group).

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.

share|improve this answer
    
Couldn't the general advice for the width of the figure be to always use \linewidth? –  Will Robertson May 1 '11 at 3:08
1  
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.) –  Will Robertson May 1 '11 at 12:45
3  
@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 May 1 '11 at 13:10
1  
@Martin: this is the correct way. Exchanging the first two tokens is quite the same (if \par is primitive \par), while exchanging the last two is disastrous. –  egreg Jul 8 '11 at 17:16
1  
@egreg: Thanks a lot again! (I really have to read the TeXBook again, or just the chapters I skipped last time ;-) ) –  Martin Scharrer Jul 8 '11 at 17:18

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

share|improve this answer
10  
Thanks Herbert, but it would be really nice to have some general explanation for this lengths, for one- and two-column mode. –  Martin Scharrer Apr 29 '11 at 16:34

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

share|improve this answer
    
This is always the type of answer I'm looking for :) –  Mario S. E. May 12 at 14:34

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.