\savebox 내에 공간이 없으면 오른쪽 정렬된 텍스트를 다음 줄로 이동합니다.

\savebox 내에 공간이 없으면 오른쪽 정렬된 텍스트를 다음 줄로 이동합니다.

이것은 이전 질문에 대한 후속 조치입니다.공간이 없으면 오른쪽 정렬된 텍스트를 다음 줄로 이동합니다.. 이제 차이점은 이 형식화된 텍스트를 \savebox. 실제 사용 사례에서는 성능상의 이유로 기존 텍스트를 따라야 하는 텍스트(예: 같은 줄)를 캐시하고 있으며, 이 캐시된 텍스트에는 페이지 가장자리에 오른쪽 정렬되는 일부 텍스트가 포함되어 있습니다.

나는 네 가지 솔루션을 모두 사용하려고 시도했습니다.공간이 없으면 오른쪽 정렬된 텍스트를 다음 줄로 이동합니다.간단한 \hfill. 이것들은 모두 외부에서 사용될 때 작동하는 것처럼 보이지만 \savebox내부에서는 작동하지 않습니다 \savebox.

여기에 이미지 설명을 입력하세요

노트:

  • 저 할 수 있어요~ 아니다\parbox{\linewidth}{}라인의 어디에서 시작될지 모르기 때문에 사용하십시오 \savebox. 즉, 같은 줄에 텍스트가 있습니다.~ 전에\usebox적용됩니다.
  • XXX원하는 버전은 텍스트 와 마찬가지로 오른쪽에 정렬 됩니다 ZZZ.

암호:

\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}

답변1

에서 \parbox주어진 너비를 사용하는 옵션linegoallinegoal패키지:

\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}

여기에 이미지 설명을 입력하세요

답변2

여기에 이미지 설명을 입력하세요

\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}

관련 정보