Text Formatting ⇒ Calculate actual text width
-
- Posts: 3
- Joined: Wed Feb 16, 2011 7:36 pm
Calculate actual text width
I have a raggedright section within a parbox. I want to calculate the length of the last line in this section. Unfortunately \settowidth doesn't work here. Any suggestions?
Cheers
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
Calculate actual text width
-
- Posts: 3
- Joined: Wed Feb 16, 2011 7:36 pm
Calculate actual text width
Code: Select all
\documentclass{article}
\newlength\mylength
\begin{document}
\parbox{50pt}{\raggedright The quick brown fox jumps over the lazy dog}
\settowidth{\mylength}{\raggedright The quick brown fox jumps over the lazy dog}
\the\mylength
\settowidth{\mylength}{\parbox{50pt}{\raggedright The quick brown fox jumps over the lazy dog}}
\the\mylength
\end{document}
Calculate actual text width
Code: Select all
\documentclass{article}
\usepackage{linegoal}
\newlength{\mylength}
\newlength{\myposition}
\begin{document}
\sloppy
\noindent\parbox{50pt}{\raggedright The quick brown fox jumps over the lazy dog.\global\setlength{\myposition}{\linegoal}}
\noindent\setlength{\mylength}{50pt}%
\addtolength{\mylength}{-1\myposition}%
\noindent 50pt minus \the\myposition\ is \the\mylength
\bigskip
\noindent\parbox{50pt}{\raggedright The quick brown fox jumps over the lazy puma.\global\setlength{\myposition}{\linegoal}}
\noindent\setlength{\mylength}{50pt}%
\addtolength{\mylength}{-1\myposition}%
\noindent 50pt minus \the\myposition\ is \the\mylength
\end{document}
-
- Posts: 3
- Joined: Wed Feb 16, 2011 7:36 pm
Re: Calculate actual text width
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Calculate actual text width
If so, then please mark the topic (not the last post) accordingly as written in Section 3 of the Board Rules (to be read before posting).theprofessor wrote:[…] Seems to be working fine. […]
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10