# How does LaTex calculate \linewidth in a twocolumn document?

I want to calculate the ideal size of figures that I export from R and include in LaTeX documents (so the text size of the figure labels is in a known proportion to the font size of the resulting document). However, for twocolumn documents I don't know how LaTeX calculates \linewidth. Is there a formula on how to calculate this? I would need something like:

(paperwidth - margins)/2 - distance_of_the_columns_as_a_function_of_font_size


Of course, I could compile the pdf and include

\the\linewidth


to get the linewidth of the current document (which I could then provide manually to R), but I want to write a R script that I can run "blindly" and that calculates the required values from the plain .tex file automatically.

Edit: I tested

\the\columnsep


for 8pt, 10pt, 11pt and 12pt article and scrartcl documents and always got 10pt, hence I assume the value is constant for regular cases. This will make things fairly easy, since \columnwidthwill then be:

(\paperwidth - margins - 10pt)/2

• \linewidth doesn't have a fixed value: it changes if you're in a list environment, for instance. What you want is \columnwidth. – egreg Aug 29 at 10:32
• Thanks, yes I think with the answer of David I'll get the correct results when I implement a calculation of \columnsep. Then I'll just use (paperwidth - margins - columnsep)/2 for \columnwidth. I think the number of font sizes and paper formats I use is limited, so I can just include the respective \columnsep-values in an if then else statement (y) – Manuel Popp Aug 29 at 10:39

The calculation is

\def \twocolumn {%
\clearpage
\global\columnwidth\textwidth
\global\divide\columnwidth\tw@
\global\hsize\columnwidth
\global\linewidth\columnwidth


That is \linewidth is \columnwidth which is half of \textwidth after subtracting the column sep (10pt in article class).

\textwidth is set in each document class in different ways (and is often re-set by packages such as geometry) by default, in article class with the default 10pt option it is set by

\if@compatibility
\if@twocolumn
\setlength\textwidth{410\p@}
\else
\setlength\textwidth{345\p@}
\fi
\else
\setlength\@tempdima{\paperwidth}
\setlength\@tempdimb{345\p@}
\if@twocolumn
\ifdim\@tempdima>2\@tempdimb\relax
\setlength\textwidth{2\@tempdimb}
\else
\setlength\textwidth{\@tempdima}
\fi
\else
\ifdim\@tempdima>\@tempdimb\relax
\setlength\textwidth{\@tempdimb}
\else
\setlength\textwidth{\@tempdima}
\fi
\fi
\fi
\if@compatibility\else
\@settopoint\textwidth
\fi


which is more or less 345pt or 2in less than \paperwidth`