General ⇒ Text width, height variable manipulation
Text width, height variable manipulation
Say I have string "my string". I than assign width to variable mvar1=width("my string"). Than I would like to use mvar1 in formatting another object say "another string" like this: width("another object")=mvar1*0.5.
Is it somehow possible in TeX or LaTeX? I wouldn't hope for exact solution. Just the name of book or webpage which to read would suffice. Any other advice will be wellcome.
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
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Text width, height variable manipulation
Code: Select all
\documentclass{article}
\begin{document}
\newlength{\stringlngth}
\settowidth{\stringlngth}{Wally Wombat}
Wally Wombat\par
\rule{\stringlngth}{10pt}
\settowidth{\stringlngth}{This is a speacial test}
This is a speacial test\par
\rule{\stringlngth}{10pt}
\end{document}
Text width, height variable manipulation
Say I have many thousands of such strings which I need to measure. I can generate code in R project into txt file like following:
Code: Select all
\settowidth{\stringlngth1}{string1}
\settowidth{\stringlngth2}{string2}
\settowidth{\stringlngthn}{stringn}
Is it possible to sink thoose values into txt file for example in following format?
stringlngth1=100px
stringlngth2=150px
stringlngthn=250px
Can I measure other objects like minipage, table cell or graphic elements?
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Text width, height variable manipulation
Yes and no. Probably. I have no idea what you are trying to achieve in the end.triop wrote:Can I measure other objects like minipage, table cell or graphic elements?
Maybe start with explaining your goal, there might be a better way.
Text width, height variable manipulation
For example I can dynamically set tabular data in pretty table using \longtable. Some things still bothers me. I have attached my table for illustration.


1a) I have to "manually" sellect columns which I want to print on one page and size of text in column headers and rows. This is not usually problem but I want also fully automatic table printing of long and wide tables. It seems that Longtable package can print only a long table but not a wide table. Wide table is typset outside page area. Any sollution?
1b) Some column headers and also cells with my data may have long strings of more than 20 words others are very short. I have written some algorithms in R which breaks each string into parts and than I wrap the parts like this \thead{It is\\ a good \\ day sir} using package \makecell. The problem is, I can't easily predict width and height for all strings when each string is typeset with different font and size.
What I would like to do is rather complex:
For example I have multicolumn with 3 columns, main header and 3 subheaders. I want to minimize white spaces in columns so that maximum of columns can fit to page.
I would like to set it with following conditions:
2a) width of the subcolumns is computed such that for example each cell has no more than 4 rows nor has greater width than the longest word in whole column except heading. No orphan short strings allowed.
2b) with 2a) I have conditions for minimal subcolumns widths. With these I can format column headding and subheaddings. Set fontsize and rotate them according an algorithm for example:
-font size is not bellow 10
-max. rows 3
-if sum of subcolumns widths is lover than width of heading give space to subcolumns equally. (Using multicolumn all space goes to last subcolumn.)
-if it results in to much space in any subcolumn try to break strings in columns with different parameters.
If I can sink size variables in txt I can possibly achieve everything described and much more.
Thank you very much dear reader to read it this far. Any advice is welcome.
Text width, height variable manipulation
Code: Select all
\documentclass{article}
% \usepackage[verbose]{geometry}
\begin{document}
% \SweaveOpts{concordance=TRUE}
\newlength{\mylength}
\settowidth{\mylength}{some text}
\the\mylength
\end{document}
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Text width, height variable manipulation
Code: Select all
\documentclass{article}
\usepackage{listings}
% \usepackage[verbose]{geometry}
\begin{document}
% \SweaveOpts{concordance=TRUE}
\newlength{\mylength}
\settowidth{\mylength}{some text}
\newwrite\triopSavedLengths
\immediate\openout\triopSavedLengths=triopSavedLengths.txt\relax
\immediate\write\triopSavedLengths{\the\mylength}
\immediate\closeout\triopSavedLengths
\lstinputlisting{triopSavedLengths.txt}
\end{document}