I'm writing a thesis template, I want to underline and centering the title. One line has a length of 5cm. When the title is too long to type in one single line, I have to put it in two, three even more lines, like this
I want to breaklines automatically, is there any good ideas? I simplify my demand (maybe not) and I put my ideas below, but I met many problems.
I have a tring a, which is somewordssomewords
.
\newcommand{\a}{somewordssomewords}
I want do cut it into some pieces, which length is 5, and underline them seperately, like
I want to do this as follow:
- use
\StrLen{\a}
fromxstring
package to get\a
's length, which is 18 - use
\fpeval{\StrLen{\abc}/5}
fromxfp
package to get how many pieces I should cut, in this example, we denote it as 3.6 - and I want to use
\foreach
frompgffor
package and\underline{\StrMid{\a}{5*(\x-1)+1}{5*\x}}
to get underlined "somew", "ordss", "omewo", and "rds"
My problem are,
- I can't use
\fpeval{\alen/5}
\documentclass{article}
\usepackage{xfp, xstring}
\newcommand{\abc}{somewordssomewords}
\begin{document}
\fpeval{\StrLen{\abc}/5}
\end{document}
error is
! You can't use `\let' after \the.
<argument> \let
l.5 \fpeval{\StrLen{\abc}/5}
?
How can I get how many pieces I shout cut?
- How to use
\x
in\foreach
to calculate. For example, use something like this
\foreach \x in {1, 2, 3}{2*\x}
to get 246.
- Is there some loop sentence like
while \StrLen{\a} > 5
cut left 5 words and underline
\a = string cutted the left 5 words
end
If there is, my work will be easy
\StrLen
isn't expandable so you can't use it inside\fpeval
.