77

For sizing figures in LaTeX it's helpful to know how wide the text is so that figures can be sized to match without rescaling. LaTeX provides \textwidth for reference by other commands, e.g.
\includegraphics[width=\textwidth]{figure}
but including \textwidth "raw" in the document produces errors.

Is there a way to determine what this value is?

3

4 Answers 4

118

From http://www.latex-community.org/forum/viewtopic.php?f=5&t=2712

Using \the\textwidth will allow you to see the value LaTeX is using. However, the default unit of measurement is probably points, not a likely option for your graphics software.

Fortunately, the conversion function is available in the standard layouts package: \usepackage{layouts}
...
textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
will print the value in cm. All the usual LaTeX units of measurement are also available if cm aren't what you want.

3
  • 18
    textwidth in inches: \printinunitsof{in}\prntlen{\textwidth}
    – Sean
    Commented Oct 14, 2013 at 11:10
  • 4
    For the article class, this gives the result 4.7747 inches. Commented Sep 21, 2015 at 15:48
  • The width in points from \the\textwidth is easily converted to cm eg. with a google search like "506.295pt in cm"
    – drevicko
    Commented May 9, 2022 at 6:06
16

The printlen package:

\documentclass{article}
\usepackage{printlen}
\begin{document}
\printlength\textwidth
\end{document}

produces "345.0pt". It can print in units other than pt, too.

5
  • printlen isn't included by default in teTeX which makes this solution a bit harder, but I'm impressed by the quick response!
    – blahdiblah
    Commented Apr 2, 2009 at 1:27
  • 2
    Just use \the, it's built into TeX itself.
    – Josh Lee
    Commented Apr 2, 2009 at 1:28
  • 1
    teTeX is unsupported for a couple of years now. You should be using TeXLive instead. Commented Apr 2, 2009 at 2:34
  • Thanks for the heads up about teTeX. Once TeXLive makes it into fink's repository I'll gladly move to it.
    – blahdiblah
    Commented Apr 3, 2009 at 23:15
  • report class appears to be 390pt in case anyone needs to know in the future
    – Hanmyo
    Commented May 27, 2017 at 2:34
2

Here is an option with pgf

% !Mode:: "TeX:UTF-8"
\documentclass{article}
\usepackage{pgf}

\begin{document}
\noindent
\the\textwidth \\
\pgfmathparse{\textwidth}
\pgfmathresult pt \\
\end{document}

where \pgfmathparse returns \textwidth in points but without unit to \pgfmathresult, so you have to manually add unit to it

length

however you know it is always in points.

1

I encountered the same challenge. However, I did not manage to use the abovementioned options. My LaTeX distribution did not recognized \printinunitsof as a valid statement.

What worked perfectly fine for me was to take a screen shot of the PDF and measure the width of the text and the width of the document in pixels using a programme like Paint. As the total document width in cm is known, you can calculate:

textwidth_cm = documentwidth_cm*textwidth_pixels/document_pixels

The textwidth is also equal to the documentwidth minus the left and right margins. If you explicitly specify the margins (e.g. with the geometry package), the textwidth is also easily calculated.

You must log in to answer this question.

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