
Dies ist eine Fortsetzung meiner früheren FrageRechtsbündigen Text in die nächste Zeile verschieben, wenn kein Platz vorhanden ist. Der Unterschied besteht jetzt darin, dass ich diesen formatierten Text in ein einfügen muss \savebox
. In meinem tatsächlichen Anwendungsfall speichere ich aus Leistungsgründen den Text im Cache, der auf vorhandenen Text folgen muss (d. h. in derselben Zeile), und dieser zwischengespeicherte Text enthält Text, der rechtsbündig am Seitenrand ausgerichtet werden muss.
Ich habe versucht, alle vier Lösungen gleichzeitig zu verwenden.Rechtsbündigen Text in die nächste Zeile verschieben, wenn kein Platz vorhanden istzusammen mit einem einfachen \hfill
. Dies alles scheint zu funktionieren, wenn es außerhalb des verwendet wird \savebox
, aber nicht innerhalb des \savebox
:
Anmerkungen:
- Ich kannnichtverwenden
\parbox{\linewidth}{}
, da ich nicht weiß, wo auf der Linie die\savebox
beginnen wird. Das heißt, es gibt Text in der gleichen ZeileVordie\usebox
angewendet wird. - Die gewünschte Version wäre rechtsbündig,
XXX
so wie derZZZ
Text.
Code:
\documentclass{article}
\usepackage{showframe}
\newsavebox{\MyCachedResults}
% The following are from
% https://tex.stackexchange.com/questions/91548/bump-right-aligned-text-to-next-line-iff-no-room
\newcommand*{\BumpCarlisle}[1]{% https://tex.stackexchange.com/a/91556/4301
{\rightskip\fill\parfillskip-\rightskip
\linepenalty100
\exhyphenpenalty0
\linebreak[0] % <-- Need space here
%Space before \hspace* allows for a break before it
\hspace*{\fill}#1}%
}
\newcommand*{\FillLineEgreg}[1]{% https://tex.stackexchange.com/a/91564/4301
{%
\nobreak\hfill\penalty50\hskip1em\null\nobreak
\hfill#1%
\parfillskip=0pt \finalhyphendemerits=0 \par%
}%
}
\newcommand{\signed}[1]{%https://tex.stackexchange.com/a/91563/4301
{%
\leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
\hbox{}\nobreak\hfil#1%
\parfillskip=0pt \finalhyphendemerits=0 \endgraf%
}%
}
\newcommand*{\FillLineTohecz}[1]{%
\raggedright
\parfillskip-\rightskip
\looseness=-1 % <-- Need space here
%Space before \hspace* allows for a break before it
\hspace*{0pt plus 1fil}%
#1%
}
\begin{document}
\bigskip\noindent
\savebox{\MyCachedResults}{Inside Savebox Carlisle: \BumpCarlisle{XXX}}%
Outside Savebox Carlisle: \BumpCarlisle{ZZZ}\par
\noindent
Text \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{Inside Savebox egreg: \FillLineEgreg{XXX}}%
Outside Savebox egreg: \FillLineEgreg{ZZZ}\par
\noindent
Some Text \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{Inside Savebox Seamus: \signed{XXX}}%
Outside Savebox Seamus: \signed{ZZZ}\par
\noindent
A bit of text \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{Inside Savebox tohecz: \FillLineTohecz{XXX}}%
Outside Savebox tohecz: \FillLineTohecz{ZZZ}\par
\noindent
Text before the bump \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{Inside Savebox hfill: \hfill XXX}%
Outside Savebox hfill: \hfill ZZZ\par
\noindent
Some more text \usebox{\MyCachedResults}%
\end{document}
Antwort1
Eine Option mit einer \parbox
Breite von gegeben durch linegoal
aus demlinegoal
Paket:
\documentclass{article}
\usepackage{showframe}
\usepackage{linegoal}
\newsavebox{\MyCachedResults}
% The following are from
% http://tex.stackexchange.com/questions/91548/bump-right-aligned-text-to-next-line-iff-no-room
\newcommand*{\BumpCarlisle}[1]{% http://tex.stackexchange.com/a/91556/4301
{\rightskip\fill\parfillskip-\rightskip
\linepenalty100
\exhyphenpenalty0
\linebreak[0] % <-- Need space here
%Space before \hspace* allows for a break before it
\hspace*{\fill}#1}%
}
\newcommand*{\FillLineEgreg}[1]{% http://tex.stackexchange.com/a/91564/4301
{%
\nobreak\hfill\penalty50\hskip1em\null\nobreak
\hfill#1%
\parfillskip=0pt \finalhyphendemerits=0 \par%
}%
}
\newcommand{\signed}[1]{%http://tex.stackexchange.com/a/91563/4301
{%
\leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
\hbox{}\nobreak\hfil#1%
\parfillskip=0pt \finalhyphendemerits=0 \endgraf%
}%
}
\newcommand*{\FillLineTohecz}[1]{%
\raggedright
\parfillskip-\rightskip
\looseness=-1 % <-- Need space here
%Space before \hspace* allows for a break before it
\hspace*{0pt plus 1fil}%
#1%
}
\begin{document}
\bigskip\noindent
\savebox{\MyCachedResults}{\parbox[t]{\linegoal}{Inside Savebox Carlisle: \BumpCarlisle{XXX}}}%
Outside Savebox Carlisle: \BumpCarlisle{ZZZ}\par
\noindent
Text \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{\parbox[t]{\linegoal}{Inside Savebox egreg: \FillLineEgreg{XXX}}}%
Outside Savebox egreg: \FillLineEgreg{ZZZ}\par
\noindent
Some Text \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{\parbox[t]{\linegoal}{Inside Savebox Seamus: \signed{XXX}}}%
Outside Savebox Seamus: \signed{ZZZ}\par
\noindent
A bit of text \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{\parbox[t]{\linegoal}{Inside Savebox tohecz: \FillLineTohecz{XXX}}}%
Outside Savebox tohecz: \FillLineTohecz{ZZZ}\par
\noindent
Text before the bump \usebox{\MyCachedResults}%
\bigskip\noindent
\savebox{\MyCachedResults}{\parbox[t]{\linegoal}{Inside Savebox hfill: \hfill XXX}}%
Outside Savebox hfill: \hfill ZZZ\par
\noindent
Some more text \usebox{\MyCachedResults}%
\end{document}
Antwort2
\documentclass{article}
\usepackage{showframe}
\newsavebox{\MyCachedResults}
% The following are from
% http://tex.stackexchange.com/questions/91548/bump-right-aligned-text-to-next-line-iff-no-room
\newcommand*{\BumpCarlisle}[1]{% http://tex.stackexchange.com/a/91556/4301
{\rightskip\fill\parfillskip-\rightskip
\linepenalty100
\exhyphenpenalty0
\linebreak[0] % <-- Need space here
%Space before \hspace* allows for a break before it
\hspace*{\fill}#1}%
}
\begin{document}
\bigskip\noindent
\savebox{\MyCachedResults}{Inside Savebox Carlisle: \BumpCarlisle{XXX}}%
Outside Savebox Carlisle: \BumpCarlisle{ZZZ}\par
\noindent
Text \unhbox\MyCachedResults
\end{document}