Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass{article}
- usepackage{lipsum}
- makeatletter
- endlinechar=-1
- newcountshortvbox@lines
- % #1: Number of lines in the final box
- % #2: Width of the box
- % #3: Text
- longdefshortvbox#1#2#3{
- begingroup
- setbox0=vtop{hsize=#2 #3par}
- setbox2=vtop{unvcopy0shortvbox@{#1}C}
- setbox2=vtop{unvcopy0shortvbox@{#1}B}
- vtop{hsize=#2unvbox1parnoindentstrutldotspar}
- endgroup
- }
- % #1: number of lines to reassemble
- % #2: C = count lines only, otherwise also build box
- defshortvbox@#1#2{
- begingroup
- globalsetbox1=vtop{}
- if#2C
- globalshortvbox@lines=0relax
- fi
- loop
- count1=lastnodetype
- ifnumcount1=1relax % hbox
- setbox10=lastbox
- globaladvanceshortvbox@lines by if#2C 1else -1fi
- fi
- ifnumcount1=11relax % glue
- skip10=lastskip
- unskip
- fi
- ifnumcount1=13relax % penalty
- count10=lastpenalty
- unpenalty
- fi
- % message{lastnodetype=thecount1}
- edef@stop{
- ifnumcount1<0 0else
- ifnumcount1=1 1else
- ifnumcount1=11 1else
- ifnumcount1=13 1else
- 0% stop early if we don't know how to handle the last node
- fifififi
- }
- if@stop0
- else
- if#2Celse
- globalsetbox1=vtop{
- ifnumshortvbox@lines<#1relax
- ifnumcount1=1relax % hbox
- box10
- fi
- ifnumcount1=11relax % glue
- vskipskip10
- fi
- ifnumcount1=13relax % penalty
- penaltycount10
- fi
- unvbox1
- fi
- }
- fi
- repeat
- endgroup
- }
- endlinechar=`^^M
- makeatother
- begin{document}
- fbox{shortvbox{7}{5cm}{What if I have got a (possibly long) text that I would like to typeset in a 5cm wide minipage, textbf{ragged right}, so that it uses at most 6 lines?
- vskip2ex
- Basically, I would just like to ask LaTeX to typeset a piece of text so that we add line breaks as usual at most 5 times, and then the last line is truncated (with some kind of a truncation marker such as texttt{"..."}) if needed.}}
- hskip1em
- fbox{shortvbox{4}{5cm}{raggedright What if I have got a (possibly long) text that I would like to typeset in a 5cm wide minipage, textbf{ragged right}, so that it uses at most 6 lines?
- vskip2ex
- Basically, I would just like to ask LaTeX to typeset a piece of text so that we add line breaks as usual at most 5 times, and then the last line is truncated (with some kind of a truncation marker such as texttt{"..."}) if needed.}}
- shortvbox{4}{linewidth}{lipsum}
- end{document}
Add Comment
Please, Sign In to add comment