0

in Getting length as number? I've seen a way to find out the length of \textwidth.

However, when instead using for example \getlength{hey} I receive an error. That occurred when using the code of all possible answers.

I'd actually like to go even further and obtain the length of something like | {\footnotesize hey}

this is an image

Did I miss something unusually simple or is it just a standard beginner Latex problem?

UPDATE: I'd like to obtain the lengths in point as a return. Or any other small metric like sp. So say the length of | {\footnotesize hey} was equivalent to X pt I'd like to see X pt returned in the documents' PDF.

UPDATE2: Here is an example code of what I would like to use the received length for in this specific case; sorry for the inconvenience so far! Hope this clears up things.

\documentclass[a4paper,10pt]{article}

\usepackage[backend=biber, style=alphabetic, isbn=true, url=true, doi=true]{biblatex}

\usepackage{multirow} \usepackage{array} \newcolumntype{L}[1]{>{\raggedright\let\newline\\arraybackslash\hspace{0pt}}m{#1}} \newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}} \newcolumntype{R}[1]{>{\raggedleft\let\newline\\arraybackslash\hspace{0pt}}m{#1}}

\setlength{\tabcolsep}{7pt}

\usepackage{calc}

\begin{document}

\begin{tabular}{ R{107pt} | L{278pt} | }

Something & Something else \ & Something else \ & \begin{tabular}{ @{}l l L{\widthof{| some other text}} | } Some & thing & {| some text} \ Some & thing & {| some other text} \ \end{tabular} \

\end{tabular}

\end{document}

This is what I'd like to receive: enter image description here

Tork
  • 61
  • You want \newlength{\mylength} in the preamble and then \settowidth{\mylength}{hey}\getlength{\mylength} in your document. – Henri Menke Dec 29 '20 at 21:16
  • latex has a standard command \settowidth which appears to be what you are looking for, – David Carlisle Dec 29 '20 at 21:20
  • Hey thank you both! As far as I have seen and now also tried, this approach only works if I would want to set the length of a function variable to that length of | {\footnotesize hey}. I added an update to clarify :) Edit: for the purpose of what you meant (I guess) I'm currently using the package calc and command \widthof. – Tork Dec 29 '20 at 21:45
  • Your question is not at all clear but you can save the length from \settolength in a length command and then use it anywhere a length can be used. Or as you say there is \widthof from calc (which is essentially the same thing, but hiding the internal length) – David Carlisle Dec 29 '20 at 21:59
  • \newlength\zzz \settolength\zzz{| {\footnotesize hey}} the length is \the\zzz – David Carlisle Dec 29 '20 at 22:00
  • Why do you want this? (it should be fairly rare to need this in latex) – David Carlisle Dec 29 '20 at 22:01
  • please also update your title, your UPDATE edit makes it clear you want the length not a number – David Carlisle Dec 29 '20 at 22:10
  • @Tork for that use you don't need to "get the length in pt" or any other unit. If for example you want a column to be half of the current linewidth you can use 0.5\linewidth you don't need to access \the\linewidth which will show the value in pt as a string of characters . – David Carlisle Dec 30 '20 at 10:48
  • @Tork that sounds massively over complicated it is almost never necessary to measure things to lay out a table, the whole point of the tabular mechanism is that the columns align without the user needing to measure things. but with no example code impossible to say really. – David Carlisle Dec 30 '20 at 11:29
  • @DavidCarlisle I added an example code, sorry! Deleting my comments as now everything relevant should be in the question. – Tork Dec 30 '20 at 11:38

1 Answers1

2

As far as I can tell you are looking for \settowidth

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc}

\newlength\zzz \begin{document}

[hey]

\settowidth\zzz{hey}

[\hspace{\zzz}] (\the\zzz)

\bigskip

[| {\footnotesize hey}]

\settowidth\zzz{| {\footnotesize hey}}

[\hspace{\zzz}] (\the\zzz)

\end{document}

David Carlisle
  • 757,742
  • Thanks that what I needed! The package apparently sets another font which I guess changes the length of {\footnotesize hey} relative to another font? Any work around for this happening? (I've just always been using the standard font until now) – Tork Dec 30 '20 at 10:57
  • @Tork really it is impossible to guess your issue if you continue to supply no example code. If you want to ask about font sizes, ask a new question with a new title and a new complete example document that shows the issue. – David Carlisle Dec 30 '20 at 11:19