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.

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?

share|improve this question
    
How do we move this to the tex stack exchange? Is it necessary? –  Limited Atonement Dec 12 '11 at 17:37
    
See also Force stringification of a length. –  Martin Scharrer Dec 26 '11 at 23:04
add comment

migrated from stackoverflow.com Dec 26 '11 at 22:57

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 18 down vote accepted

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.

share|improve this answer
    
textwidth in inches: \printinunitsof{in}\prntlen{\textwidth} –  Sean Oct 14 '13 at 11:10
add comment

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.

share|improve this answer
    
printlen isn't included by default in teTeX which makes this solution a bit harder, but I'm impressed by the quick response! –  blahdiblah Apr 2 '09 at 1:27
    
Just use \the, it's built into TeX itself. –  Josh Lee Apr 2 '09 at 1:28
1  
teTeX is unsupported for a couple of years now. You should be using TeXLive instead. –  Will Robertson Apr 2 '09 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 Apr 3 '09 at 23:15
add comment

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.

share|improve this answer
add comment

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.