Graphics, Figures & Tables\the \textwidth and \the\textheight with no units

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Curious George
Posts: 9
Joined: Wed Apr 04, 2012 6:33 pm

\the \textwidth and \the\textheight with no units

Post by Curious George »

Here is the context: In beamer presentations, I often include slides which display a number of color pictures from various sources, in various formats (jpg, png, pdf). I use the LaTeX picture() environment because it gives fine-grained control over exactly where and in what order the graphics should be placed. Ideally, would like to begin such a slide by

Code: Select all

\begin{picture}(\textwidth,\textheight)
telling Latex to create a picture space exactly as large as the text area of the slide, with origin in the lower left corner. But the following doesn't work:

Code: Select all

\begin{picture}(\the\textwidth,\the\textheight)
because the two "\the" commands give a number followed by a units name ("pt"). How can I get the get the number of points, but not the units, to include in a \begin{picture} command? Bonus would be to display numbers such as "0.5\textwidth" without units also, as arguments to the "\put" command.

Thanks for any asistance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

\the \textwidth and \the\textheight with no units

Post by Stefan Kottwitz »

You could use \strip@pt, such as here:

Code: Select all

\documentclass{article} 
\begin{document}
\the\textwidth

\makeatletter
\strip@pt\textwidth

\strip@pt\dimexpr 0.5\textwidth\relax
\makeatother
\end{document}
Stefan
LaTeX.org admin
Curious George
Posts: 9
Joined: Wed Apr 04, 2012 6:33 pm

\the \textwidth and \the\textheight with no units

Post by Curious George »

It works - thanks, Stefan!
Here is a minimal example in the context I was looking for:

Code: Select all

\documentclass{beamer}

\makeatletter
\newcommand{\Tw}{\strip@pt\textwidth}
\newcommand{\Th}{\strip@pt\textheight}
\newcommand{\Thw}{\strip@pt\dimexpr 0.5\textwidth\relax}
\newcommand{\Thh}{\strip@pt\dimexpr 0.5\textheight\relax}
\makeatother

\begin{document}
\begin{frame}
\begin{picture}(\Tw,\Th)
\put(\Thw,\Thh){\includegraphics{FILE}}
\end{picture}

\end{frame}
\end{document}
Guess its time for me to start learning raw TeX.
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

\the \textwidth and \the\textheight with no units

Post by CrazyHorse »

Curious George wrote:How can I get the get the number of points, but not the units, to include in a \begin{picture} command? Bonus would be to display numbers such as "0.5\textwidth" without units also, as arguments to the "\put" command.
use the picture package, then there is no need for stripping the dimension

Code: Select all

\documentclass{beamer}
\usepackage{picture}

\begin{document}
\begin{frame}{foo}{}
\begin{picture}(\textwidth,\textheight)
\put(\textwidth,\textheight){\circle*{5}}
\end{picture}
\end{frame}
\end{document}
Curious George
Posts: 9
Joined: Wed Apr 04, 2012 6:33 pm

Re: \the \textwidth and \the\textheight with no units

Post by Curious George »

Thanks, that works too.
Post Reply